Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Simple Tutorial/Overview about the new Event System and Raycasters

Discussion in 'Unity UI & TextMesh Pro' started by JuanGomez, Aug 22, 2014.

  1. JuanGomez

    JuanGomez

    Joined:
    Nov 20, 2013
    Posts:
    10
    Hello everyone :)

    I wrote an small guide to deal with the new Event System and Raycasters outside the uGUI. The new system allow you to detect events and call methods without writing a line of code in 2D, 3D (and of course uGUI aswell).

    http://unitydojo.blogspot.com/2014/08/unity-46-simple-tutorial-new-events.html

    Everyone is so excited about the new uGUI, that this new amazing feature is going almost unnoticed!

    As far as I know, there is the possibility of expanding this events. Has anyone tried creating other kind of events like timers? or having a method that chains another event with some delay, for example?

    What are you thoughts in general and how do you think it could be expanded? :)

    ---- UPDATE ----

    I wrote a couple of new posts regarding Unity 4.6:
    - Unity 4.6 and Vuforia Augmented Reality: http://unitydojo.blogspot.com/2014/11/unity-46-simple-tutorial-vuforia.html
    - Unity 4.6 and Health Bars and Damage Popups: http://unitydojo.blogspot.com/2014/09/unity-46-simple-tutorial-health-bar-and.html

    Hove you enjoy them :)

    ---- UPDATE 2 ----

    I wrote another post about Unity 4.6, this time in relation with NGUI: http://unitydojo.blogspot.com/2015/01/unity-46-14-tips-to-choose-your-ui.html

    ---- UPDATE 3 ----

    I wrote yet another post about Unity 4.6. Did you know that you can add the same Events that the Unity UI Buttons have to ANY of your scripts? Check out how to do it in this Simple Tutorial!: http://unitydojo.blogspot.com/2015/08/unity-46-simple-tutorial-unity-event.html
    Cheers! :)
     
    Last edited: Aug 7, 2015
    alucardj, Barfosz, MikeTon and 5 others like this.
  2. bilke

    bilke

    Joined:
    Jul 13, 2012
    Posts:
    52
    Thanks a lot for the guide! I am also very excited about the event system and especially about this quote from Tim C:

     
  3. JuanGomez

    JuanGomez

    Joined:
    Nov 20, 2013
    Posts:
    10
    Hey, thanks for the link, here is indeed the list of Interfaces I mentioned in the blog:

    Code (CSharp):
    1.             IPointerEnterHandler,
    2.             IPointerExitHandler,
    3.             IPointerDownHandler,
    4.             IPointerUpHandler,
    5.             IPointerClickHandler,
    6.             IDragHandler,
    7.             IDropHandler,
    8.             IScrollHandler,
    9.             IUpdateSelectedHandler,
    10.             ISelectHandler,
    11.             IDeselectHandler,
    12.             IMoveHandler
     
  4. Darklite

    Darklite

    Joined:
    Aug 22, 2014
    Posts:
    1
    I was curious to see if you could hook up properties to the event system as shown in your tutorial there since they don't return type void. Turns out you totally can!
     
  5. JuanGomez

    JuanGomez

    Joined:
    Nov 20, 2013
    Posts:
    10
    Good catch!
    I believe that properties behave the same way that they use to do in the inspector, like a normal variable.
    All in all the "set()" of the property get a input parameter but returns void, so that is why is valid :)
     
  6. JuanGomez

    JuanGomez

    Joined:
    Nov 20, 2013
    Posts:
    10
  7. Corvinuz1227

    Corvinuz1227

    Joined:
    Mar 2, 2014
    Posts:
    29
    im still confuse how i can use the event system, dynamically (
     
  8. JuanGomez

    JuanGomez

    Joined:
    Nov 20, 2013
    Posts:
    10
    Hello Corvinuz.

    Using the EventSystem is actually quite easy... what do you mean dinamically? I'm not sure but this may be what you are looking for: http://docs.unity3d.com/462/Documentation/ScriptReference/Events.UnityEvent.AddListener.html :)

    By the way:

    I wrote another post about Unity 4.6, this time in relation with NGUI: http://unitydojo.blogspot.com/2015/01/unity-46-14-tips-to-choose-your-ui.html

    Cheers! :)
     
  9. Corvinuz1227

    Corvinuz1227

    Joined:
    Mar 2, 2014
    Posts:
    29
    going to check that, thanks juan.. i was making a UI manager that i dont need to distinguish what UI it is, what scene it is.. im just using a state machine(enum), but i find my coding too messy,
    by the way, i switch to event trigger from event system
     
  10. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Really cool! Wished Unity 3D mad a bigger deal about this system. Because it is awesome.

    -Mike
     
  11. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    159
    Thanks @JuanGomez for that blog post.

    I'm wondering is this EventSystem really a robust replacement for rolling your own general event system using C# events? Are they as fast as C# events? When I see searching for components by interfaces, which suggests introspection, I get a bit worried about performance for general use.
     
  12. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    321
    I was wondering the same thing, and saw this thread on reddit...

    and this pic for one person's benchmark.
     
    Juan73908 likes this.
  13. Ghopper21

    Ghopper21

    Joined:
    Aug 24, 2012
    Posts:
    159
    Yeah they are around 40x slower, but that needs to be put in perspective. One hundred UnityEvent invokes would be less than 0.04 ms total according to that benchmark. So the absolute overheads is likely negligible unless you are doing a LOT of events per frame. Likely more than worth the tradeoff given the various advantages of UnityEvents over C# events.
     
    Juan73908 likes this.
  14. Juan73908

    Juan73908

    Joined:
    Aug 20, 2013
    Posts:
    13
    I totally agree with you Ghopper21 ! This is becomes a clear advantage when you need to build systems for non-programmers or in general your artists want to mess up with unity. :)

    Thanks a lot Korindian for sharing the links! To be honest I didn't expect the 40 times difference! :O
     
  15. Barfosz

    Barfosz

    Joined:
    Apr 14, 2015
    Posts:
    2
    Thanks for the tut! I had a hard time trying to understand it on my own!