Weird behaviour with the output of a function

Hi, the function pictured below has a local variable named Result. When the character overlaps an actor, the function sets the variable with the actor itself, but only if it does implement a particular interface, otherwise it is empty.

bp1

When I try to print the actor name inside the function, the behaviour is correct: if Result is setted with an actor it prints its name, otherwise it prints nothing.

The weird thing happens when I test the output outside of the function.
At start it prints nothing, but as soon the character overlaps an actor implementing the right interface, it continuosly prints the name of the last actor the character overlapped, even when there is no overlap at all.

Note that Result is a local variable, it should be empty everytime the function is called.

Is it a bug or there is an explanation to this behaviour? Thank you.

Unless you manually reset a variable, it’ll remain to what it used to be set to.

Also the function is running OnTick, not only during the overlap.
So its perfectly normal (and i think you know that) to get constant results.

Again, unless you are manually setting the value to null/something else, you should expect to see the same output.
Is that the case?

Show us more code (spaghetti mess rather) as its kind of hard to guess whats going on from 2 half pics and a description…

This is likely the key. But we’d need some full function code to see why it’s bypassing.

Also, just to make sure…
You do have something resetting values on end overlap - right?

Thank you for your reply. Here’s the entire function:

It’s nothing fancy as you can see, only if there’s more than one overlapping actor it returns the one that the player is facing.

Here the Result variable is only setted once, but again it’s a local one, it is supposed to be empty every time the function is called (that is, every tick).
Anyway, I even tried to set it once at the beginning of the function with nothing at all, same result.

your print string is only on the true path, while i thought local variables reset too its still best practice to null them so just invalidate it on the false path

1 Like

Thank you for your advice, setting up Result with an empty actor on the false paths seems to resolve the issue. :slight_smile:
I guess that the local variable in blueprint has a peculiar behaviour.