#Custom Events Not Triggering Even If Variable Have GameObject In The Input (And a Temporal Solution)

1 messages · Page 1 of 1 (latest)

opal robin
#

Im having this issue... hmm I've been dealing with this for a while.

With a custom event connecting into the "this" input an object. so it listens to this triggered event. And I get null, despite the variable having a gameObject.

A solution I've found is to "Disable / Enable" the gameObject immediately and it fixes.

Any ideas?

#

Here's a video demonstrating the error... The variable whoGets targets the correct gameObject. Listening to this enemy death. But it's not triggering even if the variable is not null.

Temporal solution I've found:

• Deactivate the gameObject, and activate it immediately.

After doing that - the custom event triggers fine.

visual raptor
#

It could be order of operation's like the Custom Event gets the value before it was set, not sure on this though because we don't see the initial time it attempted the custom event.

opal robin
visual raptor
# opal robin Could be true if it happens always, but once I disable/enable the gameObject wit...

The reason it will work after the disable/enable is because Enable sets the Variable so it makes sense that it would work after the first try because the problem could be that whoGets2 is null initially so when given to the custom event its null and just after it triggers its no longer null and nothing sets it back to null either so even after disabling it will have its value meaning it gets triggered correctly

So basically what could be happening is:

Trigger Custom Event -> Debug.LogError -> OnEnable -> Null Check -> Set "whoGets2". This is the initial trigger.

After disabling and ReEnabling whoGets2 is no longer null so it follows the same pattern but triggers anyway

#

So either that or its somehow a bug

opal robin
#

whoGets2 was a test - to manually get the data when effect is spawned. but it fails.

im using object pool - all status effects are pre-instantiated, and when adding it to enemies - i move them from a group to "as child" of the affected enemy, so particles fx follow them. and if they die (or time ends) it deactivates and goes back to pool

#

Anyways, I dont know if there's a better or permanent fix to this... but the green square above is what I do to fix this.

visual raptor
#

Are you able to show me where you trigger enemyDeath and where you set "whoGets"

opal robin
#

This video shows the flow

visual raptor
# opal robin

What you can do is if the Trigger Enemy Death and The custom event is part of the same graph just set the variable before trigger if not you could make whoGet's a object variable then set whoGet's before triggering the enemy death

opal robin
#

The thing is that this poisonFX is not a child of the enemy on start. it is attached from elsewhere (object pooling)

#

and despite that detail - I have faced this same custom event behavior elsewhere (non dynamic / child.parenting / etc)

#

For example, some things like inputManager saved as App Variable using [ on enable, set variable inputManager (this) ]

Player doesn't react to ANY input I do (like WASD or SpaceBar) unless... well, I do exactly this: disable player, enable player.

It is not noticeable when game starts. and it fixes it. Player can use inputManager now.

#

So yeah, it's weird. I think it's a bug.

#

and this is how I managed to fix it elsewhere... now I had to do the same once again.

Just wondering if I'm doing something wrong, it's a bug or who knows what -___-

visual raptor
# opal robin

Well for this specific case you could just set the InputManger(And other related ones) on start is it not? That way you don't need to enable it to trigger On Enable

visual raptor
opal robin
#

from inputManager to player? instead of player listening to inputManager?

visual raptor
#

Yeah kinda its more like you connect the CustomEvent rather than the Trigger Custom Event

#

I will send a pic

#

Something like this

#

Reading my one out would sound like "Trigger 'Attacking' On Player" your one is more Like "Trigger 'Attacking' on Input Manager" but the player intercepts/Listens for the call and uses it

#

But i can see why you chose this though it make's it more centralized, But looking at how Visual Scripting initalizes what happens is it would call the CustomEvent to get the value first and then the OnEnable Unit would trigger, I would show you C# Code but its complicated unless you are able to ask a AI to explain it?

visual raptor