Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by OctoMan · Oct 07, 2015 at 06:24 PM · animationevent

Add Event in animation from another Gameobject

Hi i want to trigger a scripted function in the animation window with an event on a specific frame, which is in another Gameobject, is this anyhow possible?

Thanks in advance

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

5 Replies

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

Answer by FortisVenaliter · Oct 07, 2015 at 08:45 PM

You'd need to create an intermediary script that stores a reference to the object you want to receive the event. Then you can sort of 'pass it on' when the event triggers.

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 OctoMan · Oct 08, 2015 at 08:13 AM 0
Share

Thats how i did it, thanks. I just thought there might be another, easier way without wasting 3 lines of code.

avatar image NateLaw1988 · Oct 28, 2020 at 11:50 PM 1
Share

I didn't see this comment but that's how I did it too. Its a shame unity won't just let you reference the object the the script like with ui buttons. Seems like it would be simple.

avatar image
1

Answer by NateLaw1988 · Oct 28, 2020 at 11:34 PM

Hi. I had the same problem but came up with a simple answer. Place a new blank script on the object with the animation. Make a blank function and call it from the animation event. Then in the blank function call the function from the other script you wanted on the other object. Worked for me. Hope it helps.

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
1

Answer by HunterAhlquist · Dec 18, 2021 at 01:17 AM

I know this is super old, but here's an example intermediary script that uses Unity Events.

 using UnityEngine;
 using UnityEngine.Events;
 
 public class ToolAnimationEvents : MonoBehaviour {
     public UnityEvent use;
     public UnityEvent altUse;
     public void Use() {
         use.Invoke();
     }
 
     public void AltUse() {
         altUse.Invoke();
     }
 }

Create as many unity events variables as you need with the associated method. It's a bit easier and less messy than creating a specialized script for every use-case.

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 dansopanso · Jan 20, 2019 at 08:59 PM

I know this is an old post but maybe someone is wondering how to 'pass on' a reference to the other collider.

Since I'm a noob this took a while to figure out :D


 public class triggerScript : MonoBehaviour
 {
     public GameObject animatedObject; 
     animationScript animationController;
 
     private void Start()
     {
         animationController = animatedObject.GetComponent<animationScript>();
     }
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.name == "TargetCube")
         {
             animationController.fadeSmall();
             animationController.kObject = other.gameObject.GetComponent<Collider>();
         }
     }          
   
 }


 public class animationScript : MonoBehaviour {
 
     public Animator animator;
     public Collider kObject;
 
     public void fadeSmall()
     {
         animator.SetTrigger("fadeBackTrigger");
     }
 
 
     private void OnFadeComplete()
     {
         destroy(kObject);
     }
 
     private void destroy(Collider other)
     {
         other = kObject.GetComponent<Collider>();       
         Destroy(other.gameObject);
         Debug.Log(other + " is destroyed");
     }
 }



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 CoolCosmos · Nov 23, 2019 at 05:51 PM

Hi, please help me, i don't know how to reference. I need to call animation from the script which is located in another gameobject. I need to do it immediately. Thanks...

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

45 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

Related Questions

Can´t find the infinite loop in this script 0 Answers

Audio event in an animation decrease its volume and stopped 0 Answers

Camera animation event to play/stop another object animation. 0 Answers

How can i call a spell whit a animation events .. 0 Answers

How to add Animation Events in the Timeline editor? 5 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