Problem with respawning Player Character.

When my player character dies. First the Actor gets destroyed then the code go to respawning the same character again but the problem that i have is that on the details on the right side the new respawned character is named “MainPlayer1” when i die again and respawn it is then called MainPlayer2 and so on. This breaks my code so any respawned character cannot use the skill tree anymore. It seems only MainPlayer0 is the only character where my code works. How can i make respawn my character as MainPlayer0 ? must be some index number the more i respawn the higher it goes. (The new repawned character is still the same with same logic it is just that is called differently - MainPlayer1 then 2,3 and so on instead of MainPlayer0 which is the real default player)

Any idea or help greatly appreciated ty.

Asset file in your content browser are Classes and when you placed/spawn a class on your level map, it become an Actor/Object, we say that actor is an instance of that class, that why you seeing thes _1, _2.

You can try to do this:


Such that it always possessed that actor whatever it instance number is.

2 Likes
  • if you have code that relies on a name of an instance, it will break sooner or later, no matter what - don’t try to ship it. I’d address this :triangular_flag_on_post: first.
  • the Game Mode can restart players, that’s one of its jobs:

It will either move an existing instance or, if none exist, create a new one. Afair.

  • or consider not destroying the pawn, hide them instead when they “die”, move them, show them

I don’t think i have code that rely on a name of an instance it is more then the code rely on on 1 specific character which is normal reference to the character BP. There is no name relying anywhere as far as i know.

Beside the problem described above with repawning a character i would like to add more character in general to the code/ my game. So far all the game code was designt around 1 character. So all the stats and skill tree/ skills and so on all was made to work with this 1 character but i would like to add more characters in this same code. So i would like to know how this can be done in a decent way that works.

Is there any way i can make maybe create a “universal” Player character ? How should i try to solve this problem in the best possible way. And i mean if i have to replace all my code and then add to it extra characters 1 by 1. Or is there some other more efficient way to do it ? I know there is this universal component that is called “Character”. What if i plug that in instead of my "Main Player Character and replace it everywhere with it?

Here is 1 example of many places like this where i will need to add more characters so the code can work with them too… “MainPlayerCharacter” is the player character i use in all the code as the 1 and only player character but recently i added more characters, so this will not work on them if i not add them here as well somehow…

I will try the restart node from your screenshot above. I use my own custom event for respawning and maybe thats a problem as it seems. Hopefully the restart node fixes it.

Edit: restart node does acctually the same thing as my custom event. It spawns new player called Player1 and Player0 can be destroyed or not doesn’t matter but Player1 or next “instance” Player2 has no more access to purchase skills from the skill tree. Wierd enough all the rest is functioning like getting xp or gold building stuff and so on crafting…

Hey there,

I have this Possess node after my character respawn kinda exactly the same as above. I can move normally with the character and is the exact same character but if it is called “Character1” then i cannot purchase my skills from my skill tree anymore. It Is like this that character1 has no more access to the code. It is the same with Character2 or 3 or 4… Only Character0 works fine and i can use my skill tree/purchase skills use them and so on.

I thought you were relying on some naming conventions but you’re not, it seems.

It depends on how the character classes work.

• if the chars are of the same class, just re-reference after respawning and it will work more than fine

• if the chars share a base class, you could use the base as variable type. And have overrides in the child classes.

• if the chars have nothing in common, you could use the native engine character class and communicate with an interface.

• worst case scenario, use an actor + interface. But that’d need to be some extreme case scenario.

• if you need access to the currently possessed char only, then just Get Pawn / Character. No need to manually reference anything ever.

1 Like

I just started testing this and it looks like i can create a child bp from my main character and everything works lol. I just need to change the mesh and animations and thats it the rest i can adjust to the new character but i don’t need to change or add anything to the code. As it is right now everything is usable stats/skills and so all is there. If this work as i tought it would then this solves any issues with adding new characters and saves me a ton of time if it really is that simple as it looks like atm…

I just see i cannot access all the bp’s in there so it will not be as simple :frowning:

Edit: I still think creating a child bp form the base bp is the way to go. I will have to clean it a bit then make a child of it and then transfer my main character there as well. This way i can make all my previous code work on all characters at the same time.

The problem with new character spawning remains tough. The only problem that it has is that the skill tree stops /refusing to purchase skills as if i had no skillpoints to do so even if afcourse i have. Not sure why this happens so far. Whitout respawning a new character the skill tree works flawless in this regard.

1 Like