x


Any pragma to tell if Unity is in release mode?

I have some assets which are not within the Resources directory, as I don't want the files to get bundled up in in the generated resource output.

Anyway due to this I have a line in a configuration file which reads like:

private static readonly string DataDirectory = "Assets/Data";

However this only works within the Unity Editor, when the build is done the data is not copied automatically so its a manual step and it ends up just being located at:

private static readonly string DataDirectory = "Data";

So is there any pragma directive available to work out if it is running as a release or not?

more ▼

asked Aug 18 '12 at 09:31 AM

Macro gravatar image

Macro
64 6 11 18

You can use String folder = Application.dataPath + "/Data";

Aug 18 '12 at 01:15 PM J.D.
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can use preprocessor tags like this:

#if UNITY_EDITOR
private static readonly string DataDirectory = "Assets/Data";
#else
private static readonly string DataDirectory = "Data";
#endif

See the Platform Dependent Compilation page in the manual

But like JD said, Application.dataPath is the easiest way.

more ▼

answered Aug 18 '12 at 01:33 PM

Bunny83 gravatar image

Bunny83
45.4k 11 49 207

Ah brilliant thanks!

Aug 18 '12 at 03:57 PM Macro
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x662
x218
x36

asked: Aug 18 '12 at 09:31 AM

Seen: 380 times

Last Updated: Aug 18 '12 at 03:57 PM