Possess already existed pawn?

I have a character A which is the main character of my game.
i have used below method to spawn another character and possess it. its works no problem till then.

but now i want to possess my previous character A (main character) without re-spawning it?
i dont know how to get reference of my main character into my 2nd character blueprint??

i just want to change characters which are inside level now i dont want to cycle characters but specifically select the one i want to select. and possess it!

You could save a reference to every character you want to use inside of your character and just use that one to change it.

If you just want it inside of your character you can create a variable of the type of your first pawn (in your second one or a reference of your second pawn in your first one), make it editable and also enable “Expose on spawn”. When you spawn it, it will create an additional pin where you can provide your other pawn to or in the case that you just spawn it inside of your character save it right after that in a variable.

I hope this was understandable^^

Cheers :slight_smile:

actually i just understood half of it… i’m still pretty much a noob…
i can do this in level blueprint easily but not in character.

can you show me a blueprint node setup… if possible?

I’m not near a computer which can run the engine until tomorrow so it’d be more ideal if I could describe it.

Basically in the details of your variables you have a few options. You can create a new one, check “Editable” and “Expose on Spawn”. When you spawn a new instance of that class you will have one more pin in which you can plug in a reference to the current character (“Self”). (Just try this part… it’ll be easier to understand :wink:

Like this that variable will be already set. Not with a default but with the character you spawned it in.

Does this help a bit more?

By what i understood i created a variable in my 1st character BP…
i have set it to my first character BP and i have checked editable and expose on spawn.
i saw in my 2nd character BP there is a new pin in SpawnActor node…
but now even after adding the return value from this node to possess “in pawn” its not switching back rather creating a new character in my game …
do i have to use this new pin somehow… if yes then where to join it??

Well you will have to check if it already exists. Since you already have variables you can just check them with the “IsValid” node. If it’s valid just swap to that one. Otherwise create a new one.

You should also right after you spawned the character save a reference to it in the character you spawned it from so when you’re back at that one you can then do the same with that variable.

this is the 2nd character graph…is this good so far… i mean i’m not getting it why i need to use transformation when i just want to switch back to my first character which is already in the game…

btw, thanks for giving time to help me…

No you’re supposed to provide the variable with the spawn event. Especially for your second character. You spawn it and because you don’T want to spawn the first character a second time you just provide it’s variable as reference. You won’t need a transform or the spawn node. Just that reference.

but then what to plug in transform… otherwise it gives error!
and how to get reference from character1st thats the whole problem!
i’m in total dark here…

Alright you have your first character. That one is spawned by the playerstart in your level and selected in your gamemode.

In there you have a reference to your second character as variable. This should be default be null or none. Simply empty. You check if it is empty and if that is true you spawn a new one. This other actor has a variable with has the “Expose on spawn” pin enabled. In there you can provide your reference from the first character. Just plug “Self” in there. Now in this second character the first is already referenced since you did that when spawning it and you can switch back.

Don’t forget to keep the reference to your second character in your first one so the second time you try to switch from it the variable for your second character is filled.

i just want to switch back to my first character which is already spawned by playstart… what you told me so far is not working at all…

if i need to use transform node in 2nd character its working i’m getting a new character in certain location… and if you are saying that i need to get the reference of first characters location and plug it into transform node… then i’m on the same problem how to get the transformation of playstart character’s current location?? even somehow i managed that but still spawning new character.

and so far i have no ideas how to use that new pin poping up in the spawn node on the left side of it…

i have also tried creating a variable of my first character in 2nd character and tried to use “get actor transformation” to plug in transform node of spawn but still doesnt work… spawning more characters instead of switching back to my first one…

…yes. Obviously. Because you use the node “Spawn Actor from Class”. I just told you like two statements ago you should forget that one together with the transform because since you already have that character spawned and at a location you will not need to set that one new. You just need to provide a reference of your first character to the “Possess” node.

This is the script you want. If you have that variable filled just possess it. Otherwise you spawn a new one and refer the spawning character as reference. You can use this script in both characters. In fact the smartest thing would be to create a parent class with this function and then just use your characters as children so you only have to write this once.
“Switch To Character” is set to “Expose on Spawn”. In this case I just spawn exactly the same character a second time.

It worked thanks alot… i was getting confused because i wasnt connecting “self” into that new pin…
thanks :slight_smile: