Download

Switching Blueprint on Input

Hi guys,

So I’m working on a game where you can shape-shift the player via a selection wheel. What I’ve done so far is created multiple Player Controller blueprints, a wolf, a bear, eagle and rabbit. Each with their own attack values and functions and mesh and what not. Now I’d like to be able to switch to each different blueprint. Only problem is I’ve scoured ze Googles and I’ve checked the AnswerHub to no avail. I have no idea in how I can toggle a blueprint class on or off and switch another blueprint class on or off. How do they talk to one another?

I’ve created a base blueprint class, with some boolean variables, but I still cannot figure out how to effectively “replace” a blueprint with another.

So yeah, any ideas in either how to achieve this or where to look to get a start would be greatly appreciated. Thanks!

Instead of creating player controllers for each type, try using different player characters. Player controllers usually persist across the game, where player characters can get destroyed and come back and be possessed. You can add your custom input controls, values and what not to the character, and have the main player controller handle what they are currently “possessing” or any other global values or controls within the game :slight_smile:

Oh excellent thank you so much. Yeah I was attempting to possess player controllers and was having so many issues. I will try doing the same with characters instead :wink:

Okay so I’ve swapped the Player Controllers out with Characters instead, but now I’m having issues with the spawning, destroying and unpossessing/possessing the other player character blueprint. Basically my master animal class seems to ignore any form of spawning and unpossessing.
9e6bbb3cc78396d9a1ddc3b142d43cf05404dfe7.jpeg
ac55bd597f09d6b7ba88cfb6d1886e5a1c4f0461.jpeg

By the looks of it your destroying the actor then trying to call functionality afterwards. I have had mixed results with this sort of flow in the past but now I try and avoid it. This could possibly fix the issue you are seeing.

I think you might also be able to possess the new character which will automatically unpossess the other… don’t quote me on that though! Play around and see if it works :slight_smile:

I’ve tried changing the blueprint around so it no longer deletes the Wolf. However, if I detach the OnBeginPlay node so it doesn’t spawn a Wolf class blueprint, and then hit the SwitchAnimal button, it works. But if the Wolf is already existing in the world (Via the OnBeginPlay being attached to the spawn Wolf class blueprint), the Bear does not spawn, nor does it Unpossess the wolf.

c9389641bde352ff86b9871d828741d93d322e97.jpeg

Just a thought, could it be due to the fact that I’m possessing another Blueprint and thus no longer being the Blueprint that controls the actual switching around?

Ok ok… so what if, I did object pooling instead?
But how would I go about possessing other blueprints while receiving the “switch-animal” input without having to replicate it for each and every animal?

[MENTION=5675]Nerd Rage[/MENTION]

The first thing, which comes into my mind (why your Wolf BP probably doesn’t spawn) is the setting in “SpawnActorFromClass”. The “Collision Handling override” is set to “Default”. Try to change it to “Always spawn, ignore collisions”. Your Wolf BP will probably now spawn at “Event begin”.

The second thing I noticed is that you use some kind of master blueprint to switch around animals. Probably you have the “Animal Master Class” set as the “default pawn class” in your “selected game mode” in the world settings.
This would mean you spawn the “Animal Master Class”, which spawns at begin play the wolf and you possess it. Now you can’t switch back again (or turn into the bear), because you unpossessed your “Animal Master Class”, which has the “SwitchAnimal Action” node.
I assume your Wolf or Bear blueprint doesn’t have spawning and possessing logic in them, right (like in your “Animal Master Class”)?