Pawn posession and savegame

Hello,

I have a game in which the player pawn is a spirit and can possess various characters. All mechanics work as designed/expected. The problem arises on level change/savegame: Since in the moment when the player is transiting levels or saves a game, it can be any of the characters it can possess. I can’t find a way to pass the relevant information to the game instance so that it spawns the appropriate character instead of the player pawn.
Another issue might be that the world isn’t procedural, so everything - including the npcs that can be possessed - is placed at design-time.

Additional info: When the player possesses an NPC, among other things, the NPC has a bool for “currentplayer” which is set to true and the player pawn gets destroyed, since it cannot possess another npc directly, not without “exiting” the current one - in which case, I just respawn the player pawn and reset the AI behavior on the NPC.

TLDR: How do I “save” or send to GI the currently possessed pawn and get it spawned instead of the default player pawn.

Any help is appreciated!
Thanks!

Before level change you want to set the class of the character in your Game Instance as a variable. Then when the new level opens set the default pawn to that class and start match. This only works this way if you have delayed start set in your Game Mode but you don’t actually need to wait. Just call start match.

Hi - first off, have you changed your game mode to not spawn any pawns? That will stop it the system automatically placing a pawn and give you control of the situation.

The save game is basically a permenent version of the GI. It’s accessibility and method of working is very similar. So you’ll be able to successfuly change levels using either, but if you want the possession situation to be correct after stopping and re-starting the game, then you need the save game.

Franky, once you’ve got the save game working, you don’t need the GI.

Let’s say you have 3 kinds of NPC: A, B, C - and your player pawn P.

When you possess, you destroy P and the player controls ( say ) B. You need to put this in the save game. How you record this is really up to you, it really depends exactly what you need when you get to the next level or replay the game.

From what you’ve said here, I’d say, current class of NPC is all you need to record. Let’s say you put the in a variable PossessedClass ( PC ).

When you get to the next level ( or re-start the game ), you just have to look in the save game and:

  1. Is PC empty?, then just spawn the default pawn for the player

  2. Is PC non-empty?, then don’t bother spawning the default pawn, just possess the NPC of class PC.

Does this make sense? If you give me more info, I will also supply more.

Thanks all for your answer. I did it another way in the end, not complicated at all:

  1. Possessed npc passes GUID to GI
  2. On beginplay (after some other code) every npc reports it’s existance to the GI (anyway, for other mechanics). It also passes the GUID. If GUID of “last npc” which got passed previously == this GUID; just run the normal possession code like it would run if done by the player.
  3. NPC (current player pawn) gets teleported to the appropriate location and the “spirit” (otherwise default pawn) gets destroyed.

Levels and GI mess with my head, especially since it’s the first time I have non-procedural worlds (in terms of NPCs/enemies etc). And are placed at design time. One would think having everything done at design time makes it easier. In my experience, procedural, data-driven spawns are way cleaner, easier to debug & less prone to dumb dev errors. Oh, well, guess it is what it is.

Thanks all for your help! Much appreciated :slight_smile: