BeginPlay does not reference player after respawn

Hello everyone.

Here the problem: I got a player which respawns after death.

In order to optimize the code and to avoid several CAST nodes, I put in some BP actors the Begin Play node that ini the Player, as follows:

In this way I can use the “MyPlayer” variable to easily reference the actor.

The problem: the object reference is set to null, probably because either the actors and the Player use both a BeginPlay node.

Quick and dirty solution: delete all BeginPlay node inside the BP actors and everytime use the Cast node. I really do not want to surrender to this.

Could you please suggest a modular approach to store and reference the Player across other BP?

Many thanks!

Hi man,
i am not sure to understand, can you define the problem a bit clearer?

if you have ActorA and ThirdPChar,
if youuse the Begin event of ActorA to set the reference to the thirdPChar , it will work until you kill and respawn that thirdPChar.
Once that is respawned you need to save the reference to the new object

Hello,
thanks for reply.

The problem appears after respawning my ThirdPChar. These BP actors placed in the level have this BeginPlay to reference my ThirdPChar.
First time works fine, but after my player is killed and respawned the Object reference is set to null.

When I respawn the Player I do:

In this case I got a new instance, but when executing the aforementioned BeginPlay inside the BP actors, the object reference for the ThirdPChar is set to null despite the cast.
I changed the code deleting the BeginPlay and substituting the “My Player” variable where it occurs with the same instruction (I mean the cast with the Player Character input set to 0): in this case everything works ok, the player gets the reference.

So, my conclusion is that it is something related to the BeginPlay node.

So, I’d like to mantain the “clean code”, without calling every time the cast in order to make it work.

EDIT: I added a Delay before referencing the ThirdPChar and everything works. BUT, I believe that this approch is not really professional.

Did you ever find another fix other than using the delay before the character reference? I’m finding myself in a similar situation and the delay works for me as well, but I too was curious if there is a more elegant solution.

Just Spawn/Respawn the character on the player controller (with server authority if needed)

then you have access to the controller for possession and the pawn for reference