Announcement

Collapse
No announcement yet.

BeginPlay does not reference player after respawn

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    Click image for larger version

Name:	init.png
Views:	39
Size:	54.8 KB
ID:	1822411


    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!

    #2
    Originally posted by Redot3D View Post
    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:
    Click image for larger version

Name:	init.png
Views:	39
Size:	54.8 KB
ID:	1822411


    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


    Comment


      #3
      Originally posted by Est_engine View Post

      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:

      Click image for larger version  Name:	respawn.PNG Views:	0 Size:	108.1 KB ID:	1822462

      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.
      Last edited by Redot3D; 10-15-2020, 08:10 AM.

      Comment

      Working...
      X