For the last several months I have been scripting in Unity, with the exception of a harddrive dieing and losing several weeks of work, I’ve gotten everything back up and running for the most part.
However, now I am suddenly getting the oddest of occurances that I can only explain as when 1 + 1 should = 2, its equaling 10.
Unfortunatly posting the slew of scripts up here isnt a good idea, and I have many scripts that tie together. As in more than 10 pages of scripts.
While I realized rather late in the game it was foolish to not simply build a message routing system, I sort of
have created one and I am currently implementing one.
Here’s the questions that I have from the odd things I am seeing:
-
Currently I am enabling and disabling scripts, quite frequently, because I only need them to run once, but I need them to run once and during a particular game state. I am noticing that by doing this, when I run the game it appears to be creating hidden instances of the scripts when they are enabled thus doubling, tripling, quadrupoling the script’s output.
Is this a common occurance? -
I have noticed that during disabling and enabling scripts, the OnEnable(), Awake(), and Start() functions are not reliable. In fact, of the three, I still have to manually call Start() even after re-enabling the script, other wise start doesnt run. I havent had any success getting OnEnable() or Awake() to work. Are these other two specific to the time of the start of the game itself? (Sort of a compound question, sorry)
-
I have a non-loop function, that loops. It loops every frame, I have to guess that something, somewhere, is calling to it from an Update(). However I am not calling to it from an Update(). I am wondering if this is some random error? The script worked literally for months, now its suddenly looping every frame, even if I force it to run once.
The closest thing is a clause I have in an Update on a script that is disabled by the latter script, then re-enabled if a specific clause is met. It ‘appears’ that it is ignoring the clause, enabling the Update() of the disabled script, thus looping itself somehow.
Yea sorry this paragraph is kinda a brain spew. -
Alot of these problems, I am hoping will be resolved with implementing a Message Router (nice one on the wiki) and using it to establish game states. Then I am hoping to simply say “If game state is this, then you can do this”.
The question here is if a message router will help me to establish these game states. Unfortunatly without a routing system right now, I have to Find gameobjects alot and check and see what state they are in. From what I understand doing this too much is a no-no, and I’m doing it ALOT. heh. -
I have an issue where currently when the player presses a specific button, it is to place an object under thier control, then check if its allowed (based on game current state) to spawn another object for placement. Even if the user taps the key like Speedy Gonzalas, 3 - 5 more objects are instantly spawned and placed. Is there a good reference for pointing someone on how to control input so it doesnt run super-fast in nanoseconds, or should I just tell it to yeild for a few seconds to slow it down?
Thanks for your input/suggestions.