Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
1
Question by Mahunreah · Feb 25, 2019 at 09:25 PM · gameobjectsetactivereferencingreference-other-object

Script is losing references once gameobjects get disabled. How can I fix this?

Hi :)

I have a couple GameObjects in my scene with tags attached. In my start function, I will store references to them in variables (this works) and disable these GameObjects afterwards, since the player doesn't need to know they are there yet (this works, too).

But now, I want to re-enable these GameObjects when the player presses a UI Button, which leads to "Object reference not set to instance of an object", which makes me tear my hair out.

Code-example looks like this; the Cape is tagged with "FF_Capa" and will be found and lost in the start-method:

 public GameObject superHeroCape;
 
 public void Start()
 {
     superHeroCape = GameObject.FindWithTag("FF_Capa");
     superHeroCape.SetActive(false);
 }
 
 public void capa ()
 {
     superHeroCape.SetActive(true);
 }

How can I make my script understand that it shouldn't lose its references?

Comment
Add comment · Show 3
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 Cornelis-de-Jager · Feb 25, 2019 at 09:30 PM 0
Share

That should work. Don't see why it would fail

avatar image Mahunreah Cornelis-de-Jager · Feb 26, 2019 at 09:06 AM 0
Share

I kind of feared this would be the case... :/ I commented the line about "setActive false" out and it was working as intended in void capa (), so it has to do with disabling it, as far as I understand. Plus, this is not the only instance of this happening; at least three other references get lost like this right after finding the corresponding GameObjects... But thank you for your input. Guess I 'll have to hope for a miracle then ;)

avatar image WarmedxMints · Feb 26, 2019 at 01:14 PM 0
Share

Are you sure the null reference is down to superHeroCape and not the object you are trying to access from the UI button

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

151 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

Related Questions

SetActive true not working on game object,GameObject not reappearing after SetActive(true) was called on it 1 Answer

Going through empty gameObject by clicking first child, destroy it then activate the next one? 1 Answer

how do i use gameObject.setactive with a bool?(my codes not working!) 3 Answers

Ok so im trying to get a string's name from another script to enable (SetActive) a certain gameObject in the scene (the player); however I keep getting errors and i have no idea what to do?? any help??? 1 Answer

Gameobject.SetActive not working on Android? 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