I have a build system for placing actors in the level and I want to add an undo feature to remove the last item built.
Issue
I am able to remove the last item built if the actor is a different asset from the build menu. If there are duplicates however it is removing the first one still. this is confirmed in the outliner when I see Actors being added and removed.
So if i have say built in order multiple gates, multiple cameras and multiple fences… It will delete
1.all of the fences
2.all the cameras
3.lastly all the cameras
You are storing the classes and not references to the actors. A class is like a prototype or blueprint of an actor. It is not it’s instance but detailed instructions how to create it.
You need to store references to the placed Actors in your scene and then access them in the undo function.
Class != Actor instance
The actor in buildables show be of type actor reference not class reference.
Useful information thank you! I have added an Actor object reference to buildables and changed the logic to match. Clearly I’m doing something wrong with my undo function now I believe?
Nothing is actually happening now but the array is being filled (print string). I guess they aren’t linked to what is being placed in the world so destroy wont work?
You need to:
a) Set buildables Ref inside of BPBuldComponent when you are adding a new struct to the array.
b) Make sure you are setting LastBuildArray via reference and not making a copy of it.
UUU a datatable. Not good. You can’t change that information at runtime. Notice all of the BuildableRef are set to none.
They should only store actor information once they have been placed in the world. If it’s a dynamic building system (that is my guess) the you won’t be able to dynamically change the datatable’s entries updating the BuildableRef position in the datatable entry.
Also at a later date you’d need to convert hard references to meshes with soft references.
If you want fully dynamic data at runtime, then you would need to use for instance an sqllite database to hold the data locally.
Unreal data tables are too basic.
Awesome, so your previous comment fixed it! I’m now using the reference from the spawned actor node, along with the cost to add to an array and remove which works as intended. Massive thank you!
As for the Datatable that’s really useful to know, I hadn’t heard of Sqllite database and clearly I have more research to do because I don’t know where to use soft references still.
All part of the journey, thank you hero of the unreal forums.
Take a look at the reference viewer. It will show how using the datatable with hard references would load up all of the meshes in each entry into memory on it’s use.
Soft references are light blue (slightly off) and class soft references are pink.
You need to load the class by hand based on the class or object so it has more steps.
Oh sorry I wasen’t clear, what i mean is would it improve performance if I changed in my datatable hard references to soft ones? like the hard reference to the actor class.