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!
1 Answer
1
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.
– kromenakNah, they worked fine in .NET 2.0 as well. My 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.
– anon85704231@kromenak Are you suggesting that it would be more efficient to expose a static update C# event
– numberkruncherEntity.OnUpdatewhich is invoked by a single controller script and then for each script that requires a per-frame updatevoid Start() { Entity.OnUpdate += ... }? Are there any disadvantages to this? Cheers