I’m running into an issue where some variables I’m setting seem to be going out of scope I think.
I have a class called BaseActorComponent (Derived from Actor Component), with a “Event Begin Play” that is saving a reference to my TDController (Derived from Player Controller) with a variable called Ref_TDController.
You can see that it is being set properly and printing out “TDController_C_0”.
The problem is that it seems to be going out of scope and I’m not really sure why.
I have a child of my BaseActorComponent called “Movement” that is grabbing what was set with Ref_TDController and printing it out, which is nothing.
I’m pretty sure I’m doing something silly or not fully understanding inheritance, but I’m not sure what.
P.S. - The Ref_TDController is not a local variable and I double checked that their are no other places where it could be setting to a Null.
What I’m hoping to do, is to cache out a reference to my TDController and anything else I might need for future use.
The reasoning being is that my units hold ActorComponents that need to speak with the TDController and it seems like a good optimization to not have constantly do a Cast every time I want to communicate.
Add an isvalid just before usage to make sure it isn’t empty. This will clear the error. You can use the Fail pin to print or call an event to SET the var, then recall the prior event.
Something is clearing it, so find all references and check your code.
Personally I’d create an event in your actor component to set the var. Then in the main actor call said event after it’s fully initialized.