Good evening everyone!
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.
Put a delay node on the event begin play.
I’m not sure what you mean Rev. How does the delay node help in this case?
I did add it in like you asked, but it didn’t seem to address my issue.
If your suggesting I put in my Delay node because something in the background needs to finish. Then I don’t think its an issue.
As running a Print statement when the Ref_TDController is being set, shows that their is a value set for the variable.
It’s when I try accessing it later in a child blueprint (Or even itself) that it yields a null value.
First check which get executed first… beginplay or the node that uses it. Work from there. It seems to me that ‘BeginPlay’ get executed later…
It helps to ensure everything is ready before it’s called.
Better yet just call an event on that actor from the primary.
So I’ve confirmed that the Delay node does not help. The BeginPlay is for sure being called first (I placed a Print node to confirm this)
It’s well over 10 seconds later that I run a different function that tries to print out my Ref_TDController variable and its returning as a Null.
Maybe try firing a timer running at 1 second interval… printing the variable content… see when it was made null…
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.