Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Feb 07, 2015 at 05:23 AM by ashleyjlive for the following reason:

There was a component loop that seemed unrelated but was somehow affecting the static variable. Problem Fixed.

avatar image
0
Question by ashleyjlive · Feb 07, 2015 at 12:37 AM · crashstaticfreeze

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 07, 2015 at 01:22 AM 0
Share

Do you have a while/do loop anywhere (other) code that uses that var? The problem desc/freeze sounds like an infinite loop.

avatar image ashleyjlive · Feb 07, 2015 at 01:47 AM 0
Share

No I don't this variable is only used by this script as of now.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges