- Home /
Compile priority - accessing static variables
I'm writing some editor extension to Asset Store, that will generate you pretty lava environment. This lava environment is scripted, so it will interact with objects. One of the scripts (normal, no-editor script written in javascript), called LavaTrigger.js have some static variables, so they can be used by other scripts:
static var PlayerInLava : boolean; // info if player is in lava
static var lavaDeath : boolean; // info if player died in lava
static var lavaHeight : float; // lava mesh height at player position
static var lavaTransform : Transform; // used to determine lava transform, for other scripts
But! Unity Assets require to put content in the main Assets folder. Referencing to this link http://docs.unity3d.com/Documentation/Manual/ScriptCompileOrderFolders.html scripts in Asset folder are compiled in phase 4. Scripts in Standard Assets are compiled in phase 1. Loot of users are creating their own scripts in Standard Assets, so any try to use those static variables (by script in Standard Assets) from script in Assets folder:
if (LavaTrigger.lavaDeath)
{
//do something
}
... will end with failure:
BCE0005: Unknown identifier: 'LavaTrigger'
So, my question is: Do i have to tell every user, that he have to move my LavaTrigger.js to Standard Assets, or there is nice solution to my problem?
Answer by HarshadK · Feb 25, 2015 at 10:48 AM
You can put your LavaTrigger.js file in 'Plugins' folder.
As per Special Folders and Script Compilation Order
Phase 1: Runtime scripts in folders called Standard Assets, Pro Standard Assets and Plugins.
So Plugins will also be executed in phase 1 along with Standard Assets folder.
But you can tell users to set their script execution order if they still come across this error.
Problem is i would have to create Plugins folder directly in Assets folder:
Assets/Plugins/LavaTrigger.js
Path like...
Assets/some folder/Plugins/LavaTrigger.js
...is not working anymore. I was hoping for some magic piece of code, like @CompileInFirstPass :), but i don't think something like that exist.
Your answer
![](https://koobas.hobune.stream/wayback/20220613184256im_/https://answers.unity.com/themes/thub/images/avi.jpg)