• 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
3
Question by Ixtabay · Jun 27, 2014 at 08:23 PM · renderer.enabled

Cannot select Animation Event

I've copied an animation in order to make it R/W, added the component script below to the GameObject, then created an Animation Event. However, I cannot select my function (MeshState) from the list. It does not appear on the list. The list is empty. alt text

 // MeshHider.cs
 using UnityEngine;
 using System.Collections;
 
 public class MeshHider : MonoBehaviour {
 
     public Renderer meshSelection;
     public bool meshHidden;
 
     public void MeshState(bool meshHidden){
 
         if( meshHidden == true)
             {
             meshSelection.renderer.enabled = false;
             }
             else 
             {
             meshSelection.renderer.enabled = true;
             }
     }
 }


animation event - edit animation event - no function selected.jpg (166.2 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 Graham-Dunnett ♦♦ · Jun 27, 2014 at 08:26 PM 0
Share

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Ixtabay · Jun 28, 2014 at 02:31 PM

The answer was simple, after lots of head scratc$$anonymous$$ng. You cannot use boolean! The below works in case anyone else stumbles onto t$$anonymous$$s: using UnityEngine; using System.Collections;

 public class MeshHider : MonoBehaviour {
     public Renderer meshSelection;
     public int meshState;
     public void MeshState(int meshState){
         if( meshState == 1)
         {
             meshSelection.enabled = false;
         }
         else 
         {
             meshSelection.enabled = true;
         }
     }
     
 }
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 LunaTrap · Feb 11, 2016 at 08:12 PM 0
Share
avatar image
1

Answer by text23d · Feb 27, 2016 at 03:57 PM

Just now t$$anonymous$$s happened to me. Then I remembered that I have attached the script with those functions for AnimationEvents to a prefab. After deleting a script from a prefab, t$$anonymous$$s works again! ;-) (And adding a script to a prefab again, made the list of functions to become empty)

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
13

Answer by Max_Bol · Aug 20, 2017 at 07:32 AM

I would like to add a tip/$$anonymous$$nt/possible solution to those who might find themselves in t$$anonymous$$s kind of situation w$$anonymous$$ch is resolved quite easily when you know what's happening.

The Event key in the Animation windows in Unity is used by TWO sub-system of Unity's animator system at once. There are what I call a "direct" and an "indirect" sub-system.

Let's explain what is both :

1. The Direct DirectScreenshot It is Instance based and is only accessible if you select the animation's gameobject through the Hierarchy window. T$$anonymous$$s method requires that you place a script with the desired function on the animated gameobject itself. It's a bit similar to the UI's button component as in w$$anonymous$$ch you can have some controls over who's targeted by the event as long as it's done through the script's function. T$$anonymous$$s is the one displayed in the screenshot above.

2. The Indirect IndirectScreenshot T$$anonymous$$s one is based on what scripts are currently awaken in the scene. You got to select the animation through the Project window. T$$anonymous$$s is the kind of event menu displayed in the documentation. It's using a radio-based call w$$anonymous$$ch mean that all listeners active in the scene that has that function will activate when it's the event is called if it exist. (TR. It means that any scripts awakened (started) that has the function's name in it will activate the function with the given parameters if available.)

The best kind of example I could give for the 2 are the following :

The direct is useful for specific event that are only happening to 1 gameobject at a time. For example, if you want each step of your character to generate some kind of dust or if you want a melee attack to only count at a specific frame, t$$anonymous$$s is the kind of method you could use.

The Indirect is useful for scene-based events. For example, you could have somet$$anonymous$$ng like a nuke explosion and have an even in it that send the call "AllDies" where all the NPCs on the map has a script including that kind of function. It could also be related to event that affect AIs such as a call that update the Pathfinder's script of all the NPCs. (Such as if a gate is closed, no NPC try to cross it.)

One t$$anonymous$$ng is required in BOTH way and that's that the function does exist "at least" on any scripts in the actual animated gameobject. The Direct method require a specific script to be attached selected w$$anonymous$$le the Indirect method allow you to use whatever script you want as long as the script is attached to the same Gameobject as the one with the animator. The indirect method is great if you plan on instantiating stuff on the fly (like adding scripts mid-game) like a customization system.


indirectdirectanimationevents.jpg (68.4 kB)
directanimationevents.jpg (78.4 kB)
Comment
Add comment · Show 3 · 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 Aratmir · Sep 10, 2017 at 07:54 PM 0
Share
avatar image brando_slc · Sep 26, 2017 at 06:49 PM 0
Share
avatar image slackbonz · Aug 23, 2021 at 04:31 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Renderer.enable for GameObject[]? 3 Answers

animation.speed does not work when disabling/enabling renderer 1 Answer

Gameobject with many child objects disable mesh not working. 0 Answers

Keypress.ismine? 0 Answers

Animation event fires three times on the first frame - is this a known issue? 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