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
0
Question by Kounex · Oct 06, 2017 at 10:30 AM · setactiveactivatedeactivate

Can't activate my deactivated GameObjects

I'm creating GameObjects based on prefabs and add them to a list. Later i want to be able to deactivate and activate those GameObjects. But all i can do is deactivate them. After that I'm not able to activate them again. Thats how i do it:

as a member variable:

 private List<GameObject> activatedModels = new List<GameObject>();


then in my method:

 GameObject newPOI = new GameObject();
 newPOI = Instantiate(this.myPrefab) as GameObject;
 this.activatedModels.Add(newPOI);

then in a public method to be accessable for another scripts:

 public void changeModelState(bool state) {
         foreach(GameObject model in this.activatedModels) {
             model.SetActive(state);
         }
     }

Deactivating my models with this method is working, but activating them again is not. I thought maybe i lose their reference after deactivating them, but the list still contains all models after doing so and I can even access their methods and so on.

Maybe someone got a clue whats wrong here? Thanks in advance! :)

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 Hellium · Oct 06, 2017 at 10:35 AM 0
Share

Are you sure :

  1. There is no deactivated parent

  2. change$$anonymous$$odelState is called twice, the first time with true, and immediately after with with false ? (Put a simple Debug.Log to check)

avatar image Kounex Hellium · Oct 06, 2017 at 10:38 AM 0
Share

Unfortunately I am. Only thing I'm deactivating in my scripts are those models and these are not bound to any other GameObjects which could be deactivated. And i checked - this method is properly being called with true and false!

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kounex · Oct 06, 2017 at 10:57 AM

I found the problem. What i didn't mention is that i made some animation for my models. I'm using the Animator to represent 3 different states: model_default, model_start and model_end. My model_default is the entry point for this animation and has the value active on false.

After initially creating this model from its prefab i call:

 newPOI.GetComponent<Animator>().SetTrigger("model_start");

where it gets scaled and active is set to true. Then I'm deactivating and activating my model again. After that it seems to reset its animation state back to model_default where active is on false!

Solution: I need to change the animation state again! Sorry for not knowing this! :x

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

71 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

Related Questions

ReActivate object with null movement ?? 2 Answers

Why does the Unity HingeJoint2D not work when enabled during play? 0 Answers

What happens to the code of the Start/Awake function when I deactivate a gameobject? 1 Answer

Activating things- What on earth am I doing wrong??? 2 Answers

Activating/Deactivating GameObject Problem :( 3 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