Search Feedback

90
votes

UnityEvent: Make UnityEventBase.Count public or add a way to determine if any listener is set at all

GUI

-

-

Right now it's not possible to determine if an UnityEvent has any dynamic listeners added by code, only persistent listener count is available.

It's possible to get UnityEventBase.Count by reflection, but you really should make this value publicly available.

One might argue that the number of listeners isn't neccessary to know. That's true, but it's important to know if ANY listener is set (so a simple HasListener property (return Count>0) will do the trick as well).

Comments (2)

  1. 980efe2dc32bade11d0d93643f5c033d?d=mm

    halken

    Dec 12, 2018 23:14

    Yes please! Note, for anyone struggling with this, I seem to be able to find the count while debugging:
    base->Non Public->m_calls->Count

    But this is not publicly available to check in code.

  2. E326c69a3e2ced285b1fdeb808f6697c?d=mm

    RElam

    Sep 03, 2015 21:10

    Yea, this seems a no brainer, there are a decent number of times where you'd want to avoid a code path before firing an event.

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(11030)

2D

(290)

Ads

(63)

AI & Navigation

(83)

Analytics

(130)

Animation

(413)

Asset Store

(370)

Asset Store Publisher

(21)

Assets

(557)

Audio

(185)

Cloud Build

(154)

Collaborate

(70)

Docs & Tutorials

(251)

Editor

(2579)

Everyplay

(17)

Game Performance Reporting

(22)

General

(1003)

Graphics

(903)

GUI

(447)

Input

(173)

Licensing

(93)

Networking

(192)

Physics

(392)

Platforms

(448)

Profiling & Optimization

(84)

Runtime

(188)

Scripting

(1154)

Terrain

(177)

WebGL

(145)