- Home /
There was a component loop that seemed unrelated but was somehow affecting the static variable. Problem Fixed.
Changing Static Variable Crashes Unity With No Error Message.
Hey,
So this is an error that I never have come across before. I have a static variable name 'power' it is in a class named SystemPower. So now I have one variable that I can alter and read from any script. SystemPower is attached to a in-game gameObject. The problem is, is that I cannot alter the variable twice. I can read it as much as I want and it works fine.
So I instantiate a gameObject. It subtracts the 'amountToConsume' variable from power and it successfully does so. Then when the same gameObject is instantiated again, it freezes; I have to use task manager to forcefully close it.
Here's the code that it gets stuck on.
void Start ()
{
if (SystemPower.power - amountToConsume < 0)
{
disabled = true;
}
else
{
disabled = false;
SystemPower.power -= amountToConsume;
}
}
If I remove "SystemPower.power -= amountToConsume;" it doesn't crash. So I doubt it's another script or anything else interfering.
I have tried Try/Catch and it does the same thing. And I have read the Editor.log file and found nothing.
I am unsure of what to do...
Cheers, Ashley.
Edit : Chucked it on another thread for this task, it works somehow. But simply accessing the scripts 'disabled' value makes it crash :/
Do you have a while/do loop anywhere (other) code that uses that var? The problem desc/freeze sounds like an infinite loop.
No I don't this variable is only used by this script as of now.
Follow this Question
Related Questions
iOS game freezes on startup 0 Answers
Webplayer Freeze / Crash After Facebook Interaction 0 Answers
Are coroutines freezing my game? 0 Answers
Main Scene keeps becoming corrupted randomly. 0 Answers
Editing Animations crashes Unity 1 Answer