Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 question was closed Jul 30, 2020 at 12:10 AM by afdal27kk for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by afdal27kk · Jul 29, 2020 at 02:24 PM · animatorgetcomponentstartawakestate machine

StateMachineBehaviour get component on awake ??

 public class StateCheck : StateMachineBehaviour
 {
     Animator anim;
 
     private void Awake()
     {
         // anim = with this animator
     }
 }

i need to get animator on awake, how can i do that ??

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 mrmatt1877 · Aug 01, 2020 at 01:10 AM 0
Share

If the animator is attached to another game object you should get it in the start method

 void Start()
 {
     anim = GameObject.Find("YourObjectName").GetComponent<Animator>();
 }

If it is attached to the same game object you could get it in awake like so

 void Awake()
 {
     anim = GetComponent()<Animator>();
 }

A good article on awake vs start: https://www.monkeykidgc.com/2020/07/Unity%20Lifecycle%20Awake%20Vs%20OnEnable%20Vs%20Start.html

I think smillyfaces is trying to recommend that you make your Animator private and make it serializable so that you can drag the object with animator into the field inside the unity editor.

like this article https://www.monkeykidgc.com/2020/07/Encapsulation.html

1 Reply

  • Sort: 
avatar image
0

Answer by smillyfaces · Jul 29, 2020 at 02:36 PM

if the animator is already attached to the game object ur script is on there is no need to have on awake for this function, another way if the animator is not attached is to make the variable at the top either [serilizable] or public.

Comment
Add comment · Show 2 · 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 afdal27kk · Jul 29, 2020 at 02:39 PM 0
Share

what do you mean ??, i want to get component the animator on statemahinebehaviour script,,

avatar image smillyfaces · Jul 29, 2020 at 02:45 PM 0
Share

one more thing u could do is create a private GameObject called animator then type in awake animator = GameObject.Find("insert object tag"); animator.GetComponent<Animator>();

Follow this Question

Answers Answers and Comments

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

Why do I get a context error when using GameObject.FindWithTag in Awake/Start function and GetComponent in a function? 1 Answer

How to apply Animator to different game objects (when animations affect children) 1 Answer

Awake called after I activate object, not after Instantiate... is it normal?? 2 Answers

How to animate the same object in the same time using built-in Animator? (for different properties, of course) 1 Answer

How to incorporate custom animations for Ethan 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