- Home /
Performance of C# Events on iPhone/Android
I'm interested in possibly using the C# event system in a game project for iphone/android, but I'm curious about the performance costs/benefits associated with using this over an event system on the wiki.
First off, are C# events supported in Unity? Second, are they a good solution to event-based programming in Unity? Third, do they scale well as more events/listeners are added to the scene? My main concern here is the performance ramifications on framerate.
Thanks!
Answer by Mike 3 · Mar 15, 2011 at 12:54 AM
There's no issue using c# events on iOS or Android - there should be a fairly linear performance hit from adding more listeners, which you'd expect.
If anything, you could potentially increase framerate if you register for an Update event, and propagate that event from one source, for example, instead of relying on unity's Update function
I won't comment on the quality of the event managers on the wiki, as I haven't used them, but any abstraction over a pure event will incur at least some cost, so look into them thoroughly
Great, thanks for the info! The reason I was unsure about using C# events was because all the forum posts I could find point to people using wiki event handlers...I guess thaty might have been before Unity supported .NET 2.0.
Nah, they worked fine in .NET 2.0 as well. $$anonymous$$y bet is that is that they're generally talking about events as a more abstract design, as opposed to the language feature, where you generally register for named events.
@kromenak Are you suggesting that it would be more efficient to expose a static update C# event Entity.OnUpdate
which is invoked by a single controller script and then for each script that requires a per-frame update void Start() { Entity.OnUpdate += ... }
? Are there any disadvantages to this? Cheers
@kruncher I don't think there would necessarily be a disadvantage to that approach; basically what you seem to be doing is getting the Update behavior of a $$anonymous$$onoBehavior without the class necessarily being a $$anonymous$$onoBehavior. If you are going to make it a $$anonymous$$onoBehavior anyway, I'd probably just use the Update function and be done with it.
Something we've discussed for our next project is potentially just having a main scene $$anonymous$$onoBehavior that manually calls an Update function on classes - hopefully will cut down on overhead and make it easier to follow stack traces.
We've also been using C# events pretty frequently. They seem to work fine for us, so no complaints there!
Your answer
Follow this Question
Related Questions
Eventhandlers & performance on mobile 0 Answers
Best way to create/design modular Player 2 Answers
Halo effect perfomance on mobile devices 1 Answer
iPhone 4 game lags 2 Answers
Slow Startup on iOS and Android 1 Answer