Switching BP Characters during Game Play


I have 8 BP Characters, all different Metahumans. I want to be able to switch between their Character BPs during game play by pressing C. The game starts with BP_Male1 by default. BP_Male1 I wrote the below code to try switch to new Character Metahuman BP whenever player presses C, but it doesnt work. Can anyone please show me where Im going wrong, thanks.

I’d start by putting the Destroy node after the switcheroo.

So I was told to put this code into the 3rd Person Character BP instead of the BP_Male1 . I did that and my character does switch from BP_Male1 to BP_Female1 but I cannot control the new character and I get this error message :
Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetController_ReturnValue”. Node: Possess Graph: EventGraph Function: Execute Ubergraph BP Third Person Character Blueprint: BP_ThirdPersonCharacter

Like this, when i do this, the characters dont change at all

This code does not belong in the character. It belongs in the Player Controller / Game Mode.

But you destroy the actor before the switch can happen. If you switch the order of the nodes, it should work as is.

Nah, now we’re destroying the actor that has just spawned. If you do this in the character BP:


The stuff in the red frame is unlikely to execute reliably because the actor is about to be destroyed - Pending Kill, as they call it in the UE biz. So, do the heavy lifting first, destroy last.


If you move the thing to the PC, then you can:

Just store the Transform of the old pawn before you destroy it, so the new pawn can use it. updated pic

This is nicer because the script belongs here more naturally, and the old pawn is not in the way - the new one can now spawn without having to wiggle around.

1 Like

Yes it works, thanks for all the help!!!

1 Like

I have a widget menu as well where the user can choose to click on different Avatar buttons to choose a new player. I tried copying this code above into the Widget Menu Graph but it comes up with errors. See screengrab. When user clicks on Female4, I want to spawn the BP_Female4, any suggestions cause I tried putting in GetPlayerController and BP_Female4 did not spawn.

Error message it gives : Blueprint Runtime Error: “Accessed None trying to read property Instigator”. Node: Possess Graph: EventGraph Function: Execute Ubergraph BPW Avatar Menu Blueprint: BPW_AvatarMenu

So it seems to compile now but still doesnt spawn and get the below error message

Note all the nodes that read Self. This targets the BP we’re in; we’re now in a widget - they do not have transforms, they do not have controllers either, and cannot be destroyed. Hence the errors / warning.

If you have a widget that is supposed to control character choice, create it in the Player Controller and dispatch the choice to the PC who spawns a new char.

This looks as if you were destroying the actual controller:

image

Ok, great will try that

Whenever I need functionality where a bunch of buttons need to make a choice, I approach it like so:

  • create a button with a dispatcher and call it onClick, feed an Instance Editable variable:

  • those custom buttons usually sit in some kind of container and the Instance Editable variable holds a specific class:

image

  • the PC fetches the container, binds them all:

Now each button spawns a different class.

Perfect, thanks so much.