Sign in to follow this  
  • entries
    2
  • comments
    5
  • views
    3142

Script execution order

Sign in to follow this  
VirtualRN

1270 views

Just had my first lesson in script execution order in Unity.

I have a MyMethod() within Update() that looks to a static integer set by another script. MyMethod() was not functioning because upon starting the game, the method would break due to the static int being set to 0. The static in question is dynamic but it's range is not allowed to fall to 0 per it's script. How on earth could it be 0?? Then I decided to debug.log the static in Update() and upon Start(). I found that the static was 0 in the first frame, then it would set correctly from the script that initializes it every frame after. However, just one frame of 0 was all it took to break my method within Update(). I'm sure I could get around this other ways but I found the quickest way to fix this issue was to use the script execution order in Unity. I set the script with MyMethod() to run last, allowing Unity time to initialize the static integer. I won't tell you how long it took me to diagnose this, but I'm writing this post out of relief. Anyone else encountered this?

Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now