Download

Scope bug? Variable is none unexpectedly

I have a variable called HUDManager in my blueprint. While handling the Event Tick event, this variable seems to be accessible. However, when handling the Left Mouse Button Pressed event, the HUDManager variable appears to be set to ‘None’.

There is only one instance of this blueprint in my scene, so as far as I can tell this should be the same scope, same variable, same instance of the blueprint.

I’ve attached a picture of my blueprint. There are two active breakpoints. When breaking on the ‘Branch’ node, HUDManager is defined. When breaking on the ‘Print String’ node, HUDManager is None.

Any theories are appreciated, thank you

bc8108d0a2b25a7b4050d636b9e187674776782a.png

Not sure if it will fix it, but try this… it’s also good for your performance.

Make a variable of type HUDManager.

Set it on begin play event.

Right now you are requesting it and typecasting it on every frame… not very performance friendly.

It could possibly also fix your problem. Why it is not working as it is right now I can’t figure out.

Hey thanks for your advice, you’re absolutely right. The HUDManager variable is of type ‘Actor’ for no good reason at all.

I feel like if I was coding, I wouldn’t have done it that way at all… this blueprint stuff messes with my head.

(I’ll have to try this when I get home, but honestly don’t think it will actually solve the issue)