Actor -> GetOwner( ) returning nullptr

Hello all!

Working on a multiplayer game, where I have an actor which is spawned server-side and has the playercontroller set as its owner. Further on I try to access the playercontroller with a cast(GetOwner). This is all hunky-dory 90% of the time, until randomly it will return nullptr and cause a crash.

Now obviously I could check for nullptr before using the assumed playercontroller, and I have other ways of getting the result I need (I need to access the playercontroller so I can grab a reference to the gamestate from it). However I was puzzled at the fact that GetOwner( ) was ever returning nullptr when I explicitly set it - and that the issue almost seems like a race condition as it is not consistently reproducible.

Actor’s owners are replicated as far as I can tell from looking through the definition for AActor, the OnRep does nothing but it should be replicated nonetheless.

Has anyone had any experience with Actor’s owners being lost or inaccessible? Haven’t been able to find much online with mention of this specific issue.

Thank you for any tips or pointers you may be able to provide!

are you positive that you are setting a valid playercontroller as the owner? possible that the playercontroller has been destroyed after that, but the actor is still referencing it?

Definitely a valid playercontroller. For a bit more info the flow of the game is as follows:

A unit is activated by clicking on them > when activated a HUD pops up above the unit with available actions - this HUD changes contextually based on what actions might be available - greying out and disabling input on the shoot button for example if there are no targets in range or sight. The unit actor does not have a direct reference to the playercontroller, however the unit is owned by an army actor who’s owner is the playercontroller (set earlier).

When activating an action through the UI, the playercontroller is passed to the action actor who handles all of the action resolution - at this point the playercontroller is valid.

When the action activates, the HUD is updated based on the current action, to let the player know what actions will be available in the future (cannot move after shooting).

It seems to be at that point, during the refreshing of available actions, where I try to grab the playercontroller from the army’s owner, that it returns null.

As I mentioned, simply checking for a null reference and returning early can “fix” the problem. However that feels to me more like putting off until I run into this again. I know that the playercontroller remains valid since when adding this check the game continues to run, passing the pc around and grabbing it to validate future available actions. (The army actor’s owner is never set again during this whole flow)

It very well could be that I’m missing something stupid, but I was surprised to have not found anything with respect to this specific issue of “losing” an owner.