RPG - Unity Events vs Delegate Events

Lately we’ve been using a lot of UnityEvents, as opposed to delegate events, and from what I’ve seen, they can be very similar. I was wondering what the major differences were between them, and in what situations I would use UnityEvents as opposed to delegate events and vice versa? What are their pros and cons, and how do I know which one to use in a given situation? Thanks!

UnityEvents are quite useful when you need to change things in the Editor, perfect tool for Game designers since it allows you to add things without coding anything. Use them when you need flexibility and don’t want to keep adding code to your other scripts, but keep in mind; if you prefab an Object that has an script with an UnityEvent that has an action that is not within the same or childed object the prefab won’t save that, you’ll have to change that manually in every scene.

Delegates need coding, these are great when you don’t want people changing in the editor how your event works, also when you need an event that uses multiple scripts from separate Game Objects, you won’t need to change anything manually in the editor.

1 Like

Awesome, thanks for the comprehensive and concise reply! I’ve also heard that UnityEvents tend to be slower than delegates…? Is that true? Is it something that makes a big difference when optimizing for performance?

There is some small overhead for parsing the event, but it’s insignificant unless you had thousands of attachments to the event.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms