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
1
Question by Recycling · Jan 05, 2017 at 10:25 AM · animatoranimator controlleranimationeventstate machine

State Machine Behaviour together with Animation Events

Hello!

I've recently decided to make use of the SMB's, but I stumbled upon some issues (obviously) :-) .

I was hoping to create a state machine behaviour script with some methods, which could be invoked by the animation event feature (those events we define inside an animation clip). Unfortunately, the event list is empty, even though the SMB script is attached to the same state as the animation clip.

Is it in any way possible to reference a method from SMB in an animation clip? Or are we limited to a method on a monobehaviour which is on the same object as the animator?

The whole point of it was to invoke the method on SMB from the clip, and then broadcast it from SMB as a c# event, like so:

 // this method should be invoked by an animation event
 public void OnSomethingHappened()
 {
     if (SomethingHappened != null)
             SomethingHappened();
 }

And this brings me to another issue.. According to the documentation, there are only two ways to get the reference to SMB's:

animator.GetBehaviour< T>()

and

animator.GetBehaviours< T>()

I was hoping to get the script from a concrete state (like transform.find("xxx").getComponent() ), but I could not find a corresponding method. That would allow me to reuse the same script on a few states ("Attack_Basic", "Attack_Advanced" and such).

Are these things possible in current version of Unity, or maybe I'm simply trying to utilize SMB's not the way they were supposed to be used? :-)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by L42yB · Jul 18, 2018 at 08:32 PM

For your first question, an animation event will only call a function on a script that inherits MonoBehaviour - so it won't work on a SMB script.

For the second, you can get the behaviour off an instanced game object like this:

 gameObject.GetComponent<Animator>().GetBehaviours<BehaviourName>();

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Plays well,but teleportation effect happens briefly when parenting the object to other obj 0 Answers

StateMachineBehaviour.OnDestroy is getting called by SetActive 1 Answer

"Anim A -> Anim B, Anim C -> Anim B" or "Any State -> Anim B" would there be a difference? 0 Answers

AnimationEvent has no receiver, but there is no AnimationEvent 1 Answer

Animator keeps overriding properties, though the current animation does not touch them 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