• 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 /
  • Help Room /
avatar image
Question by rakso13 · Feb 08, 2019 at 06:54 AM · scenedestroyvariableerror messagecomponent

random loss of component variable value

This thread is on hold while I'm doing some testing, my conclousions beneth seem to be incorrect, need to update everything


I'm working in 2 scenes, creating an object with an UI Image that I hooked up to a variable. Can use it without problem. Then when changing scene the variable works until i disable the image component, right after nothing happens but when i try to activate it via the variable I get a message that the component Im refering to is destroyed. I have 0 clue what is going on. pls help, just a theory, anthing im desperate. thnx

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by tormentoarmagedoom · Feb 08, 2019 at 08:45 AM

Good day.

You disable the image? How? Did you check in inspector is still there? Are ypu sure the error refears that image? Are you not destroying it? What and how are you disabling and reactivating it? Did you changed scenes.

Check and be sure at 100% with no doubt all that questions. Post the code lines that gives you the error.

Im thibking now... If you changed scenes, except for all 'NoDestoyOnLoad' objects, all other are destroyed. If you are trying to refear something from the last scene will give you that errro. You need to find that image again, and if is not active, ypu need to assign it via inspector.

Good luck! Bye!

Comment
armagedoomgamesstudio
craftingtycoon
micropowermantenimiento

People who like this

3 Show 0 · Share
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

Answer by rakso13 · Feb 08, 2019 at 03:56 PM

:void start(){

:Image comp = GetComponent();}


:public void enable(bool enable){

:comp.enabled = enable;

:debug.Log(comp);}


when enable = false, it works

when enable = true, it does not work

I get the message: missing refrence exeption: the object of type "Image" has been destroyed but you are still trying to acces it.

the function works as intended in the first scene but in other scenes I get this problem. If I go to another scene and then back to the first scene it works, but get the error. Also if I try to acces the component variable in an update loop in the same class, it works all the time. message.@tormentoarmagedoom

Comment
craftingtycoon

People who like this

1 Show 2 · Share
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 rakso13 · Feb 09, 2019 at 10:05 AM 0
Share

Update: it works if I instead have a bool that I change and depending on that the image gets enabled or disabled. But instead I change the image component in the update function. works perfect but inneficient. I also change some textcomponents for the childs of the object and i get the same problem in the function. But it gets solved in the same way

avatar image rakso13 · Feb 09, 2019 at 10:10 AM 0
Share

No wait, new Update. It seems like it's 2 separate classes that are not connected. I'm gonna have to look into some more into this

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

190 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 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 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 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 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 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 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 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 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 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

No error code? Not sure where to go? 1 Answer

Why is my scene variable losing its value? 0 Answers

What is a right approach to disign component interaction for example in damage deal/receive system? 0 Answers

Hi! I am trying to use SceneManagement, but I keep getting errors. 1 Answer

NullReferenceException: Object reference not set to an instance of an object 0 Answers


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