- Home /
How to handle UnityEvent listeners on instantiated objects
I've started delving into UnityEvents and with them being serialized I thought being able to use them as a trigger would be neat. So for example, have an event on a lever so I can use the Inspector to hook up two doors and an elevator to, and call their respective functions.
However when I have two levers with separate doors each they don't behave as I expected. The event seems to have the same signature for both instances so the levers each affect all doors. I was thinking they'd each only call the target functions they each had serialized in the inspector but there's overlap.
I'm assuming I'm misunderstanding them but I'm not sure what to do. Scrap using UnityEvents for a per-instance thing like this, or do I pass a lever ID and for each target tell it which ID to react to? Is there a way to create a new event per instance/give it a unique signature without losing all targets set up in the inspector?
Any advice is greatly appreciated. Am still a novice and trying to get a handle on decoupling things.