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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Lazy08 · Oct 14, 2013 at 09:13 PM · c#gameobjectinstantiatedestroy

References to GameObject become null

I have a C# script that is supposed to handle Quick Time Events. I have it so that the event is activated via ActivateQTE(gameObject), so that I'll know who called it. However, once the quicktime event is done, the variables I stored on activation are all Null! Specificaly, button1, button2 and called become null. Am I doing something wrong?

 bool isActive = false, canQTE = true;
 public float duration;
 float timer;
 int count;
 public GameObject key1, key2;
 GameObject button1, button2, called;
 
 public void ActivateQTE (GameObject go)
     {
         isActive = true;
         timer = 0f;
         count = 0;
         called = go;
     }
     
 void Update ()
 {
     if (isActive) {
         timer += Time.deltaTime;
         //This bit runs only once when it activates.
         if (canQTE) {
             canQTE = false;
             //Creates the buttons onscreen
             button1 = (GameObject)Instantiate (key1);
             button2 = (GameObject)Instantiate (key2);
         }
         if (timer < duration) {
             //Do QTE
         } else {
             //Here is where the issue starts. "button1", "button2" and null, so is "called"
             Destroy (button1);
             Destroy (button2);
             if (count >= clearAmmount) {
                 called.SendMessage ("QTE_Clear");
             } else {
                 called.SendMessage ("QTE_Fail");
             }
             isActive = false;
             canQTE = true;
         }
     }
 }

Thanks in advance

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 Doireth · Oct 14, 2013 at 09:19 PM 0
Share

Which values become null?

avatar image Lazy08 · Oct 14, 2013 at 09:24 PM 0
Share

$$anonymous$$y bad! I'll edit it in, but its button1, button2 and called

avatar image Doireth · Oct 14, 2013 at 09:37 PM 0
Share

Could you post the console output to help narrow it down.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chippy-cheese · Oct 14, 2013 at 10:11 PM

when you Instantiate an object make sure you do it "as GameObject". It might classified as something else like a transform. EX: button1 = (GameObject)Instantiate (key1) as GameObject;

Comment
Add comment · 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

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

16 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

Related Questions

Trouble with destroying an instantiated prefab 2 Answers

Store Game Object Into List For Later Reinstantiation? 0 Answers

Destroying childs and Instantiate [C#] 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

How to check if a game object is destroyed from array? And instantiate a new game object when a game object is destroyed? 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