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 UnbreakableOne · Apr 06, 2014 at 01:56 PM · eventdelegate

Question regarding events and event managers.

Hi,

First of all, I've done a good deal of Googling and Youtubing before asking this.

I know how to use delegate to define a signature for my events and how to define an event with said delegate and how to make other scripts to subscribe to these events.

But in all of the videos or blog posts that I found teaching this, they all were firing the event from the event manager but I want it for some other object to fire that event.

For example, say you have an SFX manager. It knows how to playback some sound effects based on some events. Let's imagine that there is a particle manager that does particle on certain events. Both these managers have interest in "GotCorrectObject" event.

So I need to raise that "GotCorrectObject" event for both of those managers so they can act accordingly. How can I do that? I do not want to raise event from inside of those event managers but raise them from outside.

And please do not forward me to one of those fat event managers, I'm aiming to learn and something simple.

Thanks.

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 fafase · Apr 17, 2014 at 09:26 PM 0
Share

This is not one of those fat event managers, more a GetComponent/Event comparative with just few lines. $$anonymous$$aybe that will help:

http://unitygems.com/getcomponent-vs-event/

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ashkan_gc · Apr 17, 2014 at 09:21 PM

You should simply have a higher level event manager which raises events which are high level game specific events. Let's say you have fire shot event for the enemy. SFX system and particle system are both interested in the event. You should register the SFX.PlayShotEffect event and particleSystem.CreateShotParticles events to be called when FireShot is raised. This is called event chaining. Messaging systems are ideal for this and similar situations.

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 matheuslr · Jun 07, 2014 at 01:46 PM

Hey, I too had some troubles trying to find the best solution for event management in Unity. So far, I wasn't able to find a proper one that satisfied my needs. So I decided to roll my own EventManager. It's a simple but effective solution to events in Unity.

I hope you don't get it as another Fat Event Manager. All I want is some feedback on the usage :)
Since it's open source, you can learn the things under the hood!

Please, check the code out at https://bitbucket.org/matheuslessarodrigues/connectr/ I'm looking for feedbacks :)

I was looking for a way to get rid of that nasty "SendMessage()". Also, I tried to keep it really simple and unobtrusive as you don't require to define classes or implement some IEvent interface. Just mark your methods as an EventHandler (with C# attributes) and trigger events with a static method call. Like this:

// Define the event with the method signature delegate void MyEvent( int, string, float );

// Listens to "MyEvent" [Handlr( typeof( MyEvent ) )] void MyEventHandlerMethod( int some, string random, float args ) { // Do your magic here :) }

// Then rais events with Connectr.Trigger( 42, "The event params", 0.5f );

Also, the subscription to events is handled by unity components automatically!

What do you think?

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

23 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

Related Questions

Is there a more efficient way to make events for keyboard key presses? 0 Answers

Navmesh event on navigation end 0 Answers

Prevent fire event from all instances. 1 Answer

How to make Delegates/Events survive assembly reload? 3 Answers

Will UnityEvent wait for completion of listeners ? 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