Destroy Object

Maybe a silly question, but is there a function in blueprints which destroys objects? Like destroy actor, or destroy component? I’m currently trying to use a custom object class instead of actor components (I have my reasons), I create objects via “Construct object from class” but can’t find a way to destroy them.

You should take a look at the principle of garbage collection: A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums
Briefly summarized, in order to delete a UObject from the memory you have to remove all references to this object, then it will be deleted in the next garbage collection cycle.

2 Likes

Sorry to bump old thread, but the link is no longer working. I’m not sure if it is better ot make a new thread or not.

If I understand correctly, setting an object variable to nothing would nullify it:


and then unreal will automatically handle the garbage collection as needed.

And further from that, as you can see I am overwriting the variable with a new class sometimes, in which case the result should be the same?

In other words, operating this way shouldn’t be an issue, even if we are creating these objects often (like having it tied to input bindings, i.e. whenever widgets are opened/closed a new “state object” is created)?

There is the Destroy() method on AActor class (so anything that inherits from it).

This destroys the actor it is called on. It is asynchronous meaning it may not do it immediately. It does it by the/at the end of the tick.

Check out the docs on the method here.

1 Like

Thats only for an Actor though. We are talking about an Object (another layer above Actor):

As far as I can tell, from blueprint there is no way to destroy it?

edit:


It looks like this is the method to do it ^, but I wonder if there is a way to call such method from in blueprints? Or perhaps its not necessary though.