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 /
  • Help Room /
This question was closed Mar 02, 2018 at 11:08 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by tuomvii · Mar 02, 2018 at 08:20 AM · scripting problemcomponent

Why is my GameObject that is attached to a script disappearing after I Play the scene.

alt text

So, my Light component keeps disappearing right after I play the scene. Does anyone know what seems to be the problem?

My console is also giving me this message: "MissingComponentException: There is no 'Light' attached to the "Kansi" game object, but a script is trying to access it. You probably need to add a Light to the game object "Kansi". Or your script needs to check if the component is attached before using it. LidOpen.Update () (at Assets/Scripts/LidOpen.cs:22)"

lidopen.png (7.4 kB)
Comment
Add comment · Show 1
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 Harinezumi · Mar 02, 2018 at 08:36 AM 0
Share

A component or game object can only disappear from the scene (without user interaction) if a script calls Destroy() on it. So there must be a script that takes your Light game object or the Light component on it and destroys it.
Possibly it is the LidOpen script itself that does it, but it can be anywhere in your scene. After checking LidOpen, I recommend a text search for Destroy(light) or Destroy( (without closing parenthesis) in all your scripts.

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by upasnavig90 · Mar 02, 2018 at 10:12 AM

hi, what happened was, @tuomvii was getting light component which was not attached to the same gameobject that of script. so he has to remove the line :

Light = GetComponent();

and he was to give the reference from outside, or use gameObject.find() function.

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
avatar image
0

Answer by NEGATIVERAGDOLL · Mar 02, 2018 at 09:14 AM

Could you show the script it is referring too? You probably destroy the object by accident

Comment
Add comment · Show 8 · 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 tuomvii · Mar 02, 2018 at 09:24 AM 1
Share

Sure,

 public Animator anim;
 public bool lidCheck;
 public Light Light;

 void Start()
 {
     anim = GetComponent<Animator>();
     lidCheck = false;
     Light = GetComponent<Light>();
 }

 void Update()
 {
     if (lidCheck == false)
     {
         Light.range = 2.0f;
     }
 }

 void OnTriggerStay (Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E))
         {
             anim.Play("openlid");
             lidCheck = true;
         }

         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.R))
         {
             anim.Play("closelid");
             lidCheck = false;
         }
     }
 }

}

avatar image upasnavig90 · Mar 02, 2018 at 09:30 AM 0
Share

is the light component attached to the same gameObject to which script is attached??

avatar image tuomvii upasnavig90 · Mar 02, 2018 at 09:33 AM 0
Share

No it is not. The script is attached to the object which is animated. The light component is in another object.

avatar image upasnavig90 tuomvii · Mar 02, 2018 at 09:36 AM 2
Share

but you are fetching light component from the same object as in this line: GetComponent();

either try gameObject.find or assign it from outside as public varible. if you are already assigning from outside just remove this line: Light = GetComponent();

Show more comments
avatar image tuomvii upasnavig90 · Mar 02, 2018 at 09:36 AM 1
Share

What I did is that I put the script to the object which i wanted to be animated. Then I put the other object which has the light component as an attachment to the public Light slot.

avatar image upasnavig90 tuomvii · Mar 02, 2018 at 09:39 AM 1
Share

i hope i helped you :)

avatar image Harinezumi · Mar 02, 2018 at 09:59 AM 0
Share

Guys, I took the liberty and converted the discussion into comments. I hope you don't $$anonymous$$d. Never $$anonymous$$d, it was upasnavig90 who helped...

Follow this Question

Answers Answers and Comments

139 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

Related Questions

How can you delete a MeshCollider?? CAN you delete a MeshCollider? 1 Answer

Storing any component inside a single variable. 1 Answer

How to write type-safe loosely coupled components 1 Answer

How to add a editing option to variables in a script in Inspector? 0 Answers

I'm receiving an error saying that "Specified cast is not valid (wrapper castclass)". 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