Trying to remove the last item in my index dose not work when I have multiples, why?

Hi all,

Brief

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

but the duplicates of each will be first to last.

What I have

Here I’m setting the array I believe:

Here I add to the array “I believe XD”:

And finally I (Should) remove the last actor added to the index:

Where am I going wrong? please and thank you :vulcan_salute:

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.

1 Like

Thank you for your response @3dRaven ,

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?



Check if Buildable Ref returns a valid reference via an isValid node and print string or debug with F9 on the node to check.

yeh, its returning not valid.

Here is how I added them to Buildables


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.

1 Like

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.

1 Like

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. :face_with_spiral_eyes:

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.

1 Like

So in my case,

With the datatable, would i be better off setting anything that is not needed on begin play or on tick to a soft reference? like my actor class.

Thanks

Tick runs every frame. Do not use it for any initialization as it will constantly be called.

Stick to begin play or on construction.

Just be sure to only spawn actors on begin play or later, as you can’t do that in on construction (it’s too early in the level lifecycle).

1 Like

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.

It would reduce memory usage.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.