Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple Tutorial/Overview about the new Event System and Raycasters

Discussion in 'UGUI & 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
    Clonkex, AlucardJay, Barfosz and 6 others like this.
  2. bilke

    bilke

    Joined:
    Jul 13, 2012
    Posts:
    54
    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:
    170
    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:
    584
    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:
    170
    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!