Download

Error with possessing player character in some levels

Hi,

I made these blueprints to spawn the correct character class blueprint and then possess it. It worked in all the levels I had but now when I create a new level it doesn’t work. When I call on the player character to do something after this code I get the error “Attempted to access Sorcerer_BP_C1 via property x but Sorcerer_BP_C1 is pending kill from function”. This only happens in new levels that i create and in my existing levels it works. I don’t get how this error can be level-based.

I tested the nodes through print strings and all seems to be happening correctly. The print string that can be seen in the screenshot, that prints the player character after the possess returns the correct name, so the class selection is happening correctly.

I thought it would be a problem with the DestroyActor node that destroys the playercharacter, so the player controller gets destroyed and the possess node cannot call it anymore, but that doesn’t seem to be the case, the controller doesn’t get destroyed with the DestroyActor node, and it’s working in my existing levels so it must be working correctly.

Any ideas why I get the error “Sorcerer_BP is pending kill” ?

Thanks in advance!

9b02055be4a42ec941c29f2e0c7809f00abd8115.png

  • Which class is your default pawn class in your GameMode? (Maybe the error is not exactly related to the new spawned actor, but the default class that is already in the game)

  • Is there any Character/Pawn already spawned in the level with Aut Receive Input set?

  • This same message occurs when you wish to spawn a Warrior?

I know this doesn’t make much sense if this was effectively working in your previous level, but that was my first thoughts after reading from your code.
Maybe you should dig into the difference between each maps.

  • The default class is Sorcerer_BP

  • There are no characters/pawn in the level. The level is just empty. Well technically, it spawns the default class that’s set in the gamemode, and the whole purpose of my code is to destroy the default character that spawns and replace it with the correct class’s character blueprint. But the default character that got spawned is set to auto receive input “disabled”

  • Yes the same message occurs when trying to load a warrior. Then the error becomes “Attempted to access Warrior_BP_C0 via property x but Warrior_BP_C0 is pending kill from function”.

  • I looked at the differences between the levels but I can’t find much. Only that the new level has PlayerStart and the old levels have NetworkPlayerStart. Don’t know if that makes a difference?

i think u should do it this way.
Make a gameInstance-> make a variable type integer, then if u chose Sorc->, set the integer to 1, warrior to 2.
Make an array of default Pawn class or pawn class, then expand its, add all your Character Class in it. Then u can come to GameMode and set in the Event begin play, cast to GameInstance, if Inter=1-> SetDefaultPawnClass = the class in the array that u chose, in this example, it is Sorc. Bump, it was done. Dont Try to destroy the default pawn class and spawn your class.
Sorry, u should put the SetDefaultPawnClass in Constructor, not in begin play event, edit :smiley:
https://www.youtube.com/watch?v=3Dt9flwdAsk&feature=youtu.be here i made a quick clip to show u how its done.

cool thanks for the movie! I will take a look at it further. It is indeed a bit nasty to destroy the default pawn and respawn the correct class. But anyway I’m going out now, it will have to wait till tomorrow :slight_smile:

Ok it works now! I ended up taking the class name from my savegame and do a switch string on those and then just set default pawn class. all in the construction script of the game mode

Thanks again! really appreciate you making a movie clip!

PosessError.png

I created a video as well on this but I’m using an enum and the Gamemode override for default class this is useful as the construction method is called once when a level is loaded and if you wanted to change your class mid level and reset the player as that, you’d likely need extra code and restarting the level completely.

The override is called everytime you reset the player

https://youtu.be/O7FFRqb8T6o

Cool, thanks! That seems to be a good way to handle things, I will take a look at it, because my current solution still has some problems going on.

Edit: Got it working flawlessly by using your method. Thanks alot! And thanks for the movie, I love this UE community so much :smiley: