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 /
avatar image
0
Question by awesomedata · Dec 29, 2014 at 01:16 AM · animatorsetactiveboolparameters

Bool Parameter does not persist through code deactivation/reactivation -- except if set in Editor!

For some reason, when I set a bool mecanim parameter as "true" through code, that setting disappears (becomes false) upon deactivating/reactivating the object through code. HOWEVER, if that parameter was set to "true" through the state machine editor (and then deactivated/reactivated through code), its setting persists through both deactivation AND reactivation (in my case, this is the desired behavior -- except I want it to do this through code too!)

Any idea how to get the setting through code to persist through deactivation/reactivation too?

Or is this a bug?

If so, is there any workaround? (I'm using 4.6.1 if that helps!) I need it to be able to remember the bool setting from code in order to fork my state transition at the start of the animation the next time it plays (i.e. after being reactivated). I'm playing an intro animation only once, then it should transition directly to the other animation state every time after that (upon being reactivated), making this decision initially upon gameobject reactivation!

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

3 Replies

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

Answer by awesomedata · Jan 01, 2015 at 01:14 AM

Finally found a solution to my own problem to work around this bug, in case someone else is having this same issue:

Use OnEnable() and OnDisable() events to store the parameter temporarily and set it again upon reactivation (i.e. use OnEnable() to set it back as soon as the object is reactivated).

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 shriya · Dec 29, 2014 at 06:16 AM

HI, I don't find any need to keep your boolean public . Try with this:

 private static yourbool;

and maintain everything through code. I hope it helps.

Comment
Add comment · Show 1 · 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 awesomedata · Dec 29, 2014 at 05:14 PM 0
Share

Sorry, but my boolean is a parameter inside the mecanim state machine that I set/get through the animator component. I need the mecanim state machine to be able to access it internally so it can deter$$anonymous$$e (via transition conditions) what animation to play.

That said, I'd hate to rewrite mecanim via code just to swap animations one time. And, even if I just used the mecanim system entirely through code, there's still no guarantee the value will persist when the object is deactivated since I'd still be using the animator component and mecanim's internal systems! D:

Perhaps the problem lies in the SetActive() function itself??

Is there any way to set the bool in a roundabout way (i.e. by modifying how the internal editor code sets the bools somehow maybe?)

avatar image
0

Answer by Wandersoul · Dec 29, 2014 at 05:57 PM

Bools are false by default. Assuming you are using C# you can define the initialized value by changing your declaration from :

 public bool flag;

to:

 public bool flag = true;

This will cause the bool to use true by default instead of false;

Comment
Add comment · Show 1 · 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 awesomedata · Dec 29, 2014 at 09:15 PM 0
Share

I'm using mecanim state machine parameters to set a Bool (and Javascript) using "animator.SetBool("mybool");" through code.

That said, I'm not finding a way around the issue with your code that allows the parameter to be remembered through deactivation/reactivation with your answer.

Any ideas on how to go about this with your solution (or at least an alternative solution)? What would the code need to look like to do this for Javascript?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animator Bool: How do you use it? 1 Answer

Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean) 1 Answer

Animator parameter stuck as True 4 Answers

How to get Animator.GetBool to work as a parameter in OnCollisionEnter in Unity (c#)? 0 Answers

Can animation parameters only be changed in scripts? 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