I have tree actors placed in world from editor. I have option to chop them down, but on new game, they respawn, obviously.
I want to make them disappear on load game.
I tried, saving actor in an actor array, that I store in playerBP and on savegame save.
It works, for 4-7tress. If i chop down more, the array values become empty. Not really sure why it forgets entries so
Also tried setting up tags for actor and On destroyed, saved the actors name in a string array.
And looped to find same names, but when i destroyed too many actors, i got infinite loop error.
I would avoid using “GetDisplayName” and use “GetObjectName” instead because instances generated at runtime might have different names. Unreal can also add extensions to names of actors in the world. If you have a tree object called “SM_Tree03” may become "SM_Tree03_355"at runtime.
To solve your problem, I would create a class with an exposed variable which allows you to disable trees.
Right click in your content browser and create a StaticMeshActor (or any actor type you need).
Call BP_MeshBase or a name which identifies that is a base class.
Open the MeshBase and create a variable called “bDestroyActorOnLoad” and add a branch check to destroy the actor on begin play…
On the variable “bDestroyActorOnLoad” make sure you check the following properties: “InstanceEditable” and “ExposeOnSpawn”
- Go back to your content browser, right click and create blueprint class. Open up all classes and select your MeshBase
Open the blueprint and add your Tree mesh. For this example, I called my actor BP_Char and used the starter content chair mesh.
Place instances of your child class in the world (you can just drag them from the content browser).
Look at the details panel, you will see that boolean we added earlier. Check it for items you want to be removed on begin play.
- Hit play for results!
I also included an example of hiding a mesh rather than destroying it, in case you need it later.