Quantcast
Viewing all articles
Browse latest Browse all 2383

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 :/

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>