Hello everyone, I’m starting to work with events but a I had a question that I a not seen directly addresses (and I apologize in advance if this question is strange or irrelevant).
-In terms of performance, is having a script that is subscribed to an event better or worse than say that same script checking for a condition in Update()?
–In my head, it would seem that the subscribed script would basically be waiting for a event every frame (or how would it know when the event was fired?). Or is the subscribed script just “available” and being subscribed just gives the event a memory reference to that method (and others)?
Any clarification is appreciated.
I found that honestly in some cases it doesn’t really matter. However, I have had times where scripts in my update have slowed the game down a bit. Now sure why as the scripts really weren’t that sophisticated. Never had it happen with a simple event.
That said, keep in mind “Events correspond to user input (key presses, mouse actions), or are UnityGUI layout or rendering events.” It’s constantly checking to see if the required trigger of the event has been triggered.
Not sure if this helped.
Use events whenever possible. As the events are (or at least more likely to be) written in a lower level language they’ll require less processes.
The difference will be mostly unnoticeable but avoidable processes should be avoided (without sacrificing some readability).