Swapping between three AI companions, and how to spawn without losing previous information (health, exp, etc)
I am currently working a project that is focused on catching, battling, and raising monsters. The player will be able to equip up to three monsters, but can only use 1 at a time. I am having a hard time setting up a blue print that allows the player to spawn and swap between the 3 equipped monsters. I have been through tutorials, and this is what I came up with:
This was placed in the level BP and allows me to spawn and actor while destroying the others. The problem with this set up is that after destroying for example companion 1 when i go to spawn companion 1 again after swapping companions it spawns as a new actor in game. How would i set this BP up to be able to spawn the companion actor again instead of losing all my health, exp, etc information? Think of something like pokemon, but instead of interchanging through 6 I only have three. Any help would be most appreciated.
asked Aug 16 '17 at 04:43 PM in Blueprint Scripting
If you plan on spawning the actor again, why destroy it? It'd be much easier to either hide or just not render it. Personally, I'd just set up an area under the map or way off to one side and move the actor there until it was needed again. Then you wouldn't have any delays and no messy code to deal with.
During begin play for your character spawn the actors in a hidden area and as you need then move them into the arean. Being only three actors the memory footprint should be fairly small also.
answered Aug 18 '17 at 06:59 PM
If you don't want to lose previous information ("health, exp, etc"), you're gonna have to store that information as variables (which you're gonna have to do anyway, if you want to save to a save file and continue where you left off).
So, one Float variable for HP, one for XP, MP, and so on. Then, when you switch to a different "monster", it each has its own HP, MP, preferably displayed on the user interface.
You don't need a "Branch" node at the front (unless you want to check first if one of your 3 monsters died or something before spawning).
And yeah, you can use a "Toggle Visibility" node instead of spawn/destroy, just like you would toggle a light source. There are several tutorials on Youtube on how to turn on/off a light, and it's the exact same thing for meshes, same result as if you would uncheck the "Visible" checkbox in the actor's details.
Constantly spawning/destroying a mesh back and forth is more stressful on the resources than just toggling the visibility of an already spawned mesh.
Follow this question
Once you sign in you will be able to subscribe for any updates here