이벤트 관련 기능을 구현할 때 C# 에서 제공하는 이벤트 (Delegate, Action 등) 대신 UnityEvent 를 사용하는 유일한 이유는 UnityEvent 가 에디터에서 사용 가능하기 때문이다. 에디터 상에서 이벤트에 드래그 앤 드랍으로 등록 할 수 있고 어떤 이벤트가 등록된 상태인지 확인 할 수도 있다.

이에 더해서 이벤트를 등록하고 사용할때 해지도 해줘야 하는데 UnityEvent 를 사용하면 이러한 등록/해지 과정에서의 실수로 인한 문제를 방지해주는 이점이 있다. 그 이유는 UnityEvent 가 weak reference 기반으로 동작하기 때문.

하지만 이러한 이점에도 불구하고 개발자가 Editor plugin 을 만드는게 목적이 아니라면 항상 native C# event 를 사용하기를 권장한다. 그 이유는 더 빠르고 메모리를 덜 사용하기 때문이다. (fast performance, small memory usage)

  

 

더 읽을거리
UnityEvent vs Delegate Event benchmark
Event Performance: C# vs. UnityEvent

 

출처 : StackOverflow

  

  

The only advantage and reason to use UnityEvent is that it allows you to use events in the Editor. That's for drag and drop people or those making Editor plugins.

Another advantage of UnityEvent is that it prevents the problem of Unity Object not being freed due to the misuse of delegates or using anonymous delegates with Unity Objects. Although they get freed when the main script that's holding them is destroyed. The reason for this is because UnityEvent is implemented with weak references therefore removing/minimizing this problem. These two things are still not worth it to use UnityEvent over native C# events.

You should always use native event and delegate over UnityEvent if you are not making an Editor plugin because of its fast performance and small memory usage. See this and this post post for more information.

+ Recent posts