Not a Bug

Custom Event grabs listener before variables are written after hitting play

Boris Vitazek 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

Hi! Simple thing

I have a custom event that holds all colliders that my player when he countered the attack, so enemies can listen to it and check if they were countered

enemies listen to player gameobject,  i set the player gameobject as scene variable with the start event

when i try to use scene variable with player game object for custom event receiver on enemies, after hitting play in editor it is Null - i have to disable and enable enemy game object to get the scene variable on the custom event:

after disable+able of enemy gameobject

i know this can be automated, its just annoying when working on things, is this by design? Could event receiver wait until end of frame? 
Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Not a Bug

Hi Boris!

Event targets are evaluated when the graph starts listening and only then, not at every frame. As you noticed, the listening start happens before the Unity start event. 

You have a few options here:

  • Set your scene player variable manually from the editor instead of from script
  • Don't enable your enemy objects until your player object has been enabled
  • Listen to the event on the player object itself

problem is, that i managed to manually assign variable only once

when I try to manually assign variable with drag n drop, it always shows Nope sing instead of mouse cursor

Hi Boris, if this is the Object Variables tab on a prefab, are you sure you're in the Instance tab? If you're on the Prefab tab, it's pointing to the variables on the prefab definition, and those do not support scene references.