Search Feedback

89
votes

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

Scripting

-

-

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 (1)

  1. E326c69a3e2ced285b1fdeb808f6697c?d=mm

    RElam

    Sep 03, 2015 23: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

(10781)

2D

(281)

Ads

(55)

AI & Navigation

(82)

Analytics

(133)

Animation

(396)

Asset Store

(355)

Asset Store Publisher

(17)

Assets

(543)

Audio

(184)

Cloud Build

(145)

Collaborate

(64)

Docs & Tutorials

(240)

Editor

(2507)

Everyplay

(19)

Game Performance Reporting

(22)

General

(980)

Graphics

(870)

GUI

(432)

Input

(173)

Licensing

(92)

Networking

(189)

Physics

(384)

Platforms

(442)

Profiling & Optimization

(85)

Runtime

(182)

Scripting

(1168)

Terrain

(172)

WebGL

(143)