Announcement

Collapse
No announcement yet.

When I remove object references from a UE4 map are they automatically destroyed?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    When I remove object references from a UE4 map are they automatically destroyed?

    In other words, does the UE4 map data structure take ownership of its object references, or does it store a pointer to them? When I remove, does it simply destroy the pointer or destroy the object (being pointed at) as well (or at least mark it for deletion when the GC is run)?
    I hope the question is understandable enough.

    #2
    Depends if you are on about an Actor or a UObject. I don't think (or maybe they have recently done it) where a Map can be accessed by the GC system if its marked UPROPERTY. Actors have to be explicitly destroyed. I don't store UObjects in a TMap so i wouldn't know. I always tend to use TArray with a struct.
    Game Programmer - Working for a Indie Studio.

    Visit my blog: TheGamesDev

    InterKaos Games

    PC Specs:

    Comment


      #3
      I am talking about a UActor. So they have to be explicitly destroyed. Alright. Thanks for the help.

      Comment


        #4
        KeyC0de more info:

        When an AActor or UActorComponent is destroyed or otherwise removed from play, all references to it that are visible to the reflection system (UProperty pointers and pointers stored in Unreal Engine container classes such as TArray) are automatically nulled. This is beneficial in that it prevents dangling pointers from persisting and causing trouble down the road, but it also means that AActor and UActorComponent pointers can become null if some other piece of code destroys them. The ultimate advantage of this is that null-checking is more reliable, as it detects both standard-case null pointers and cases where a non-null pointer would have been pointing at deleted memory.

        It is important to realize that this feature applies only to UActorComponent or AActor references marked with UPROPERTY or stored in an Unreal Engine container class. An Object reference stored in a raw pointer will be unknown to the Unreal Engine, and will not be automatically nulled, nor will it prevent garbage collection. Note this does not mean that all UObject* variables must be UProperties. If you want an Object pointer that is not a UProperty, consider using TWeakObjectPtr. This is a "weak" pointer, meaning it will not prevent garbage collection, but it can be queried for validity before being accessed and will be set to null if the Object it points to is destroyed.

        Another case where a referenced UObject UProperty will be automatically null'ed is when using 'Force Delete' on an asset in the editor. As a result, all code operating on UObjects which are assets must handle these pointers becoming null.
        https://docs.unrealengine.com/en-US/...ons/index.html

        Comment


          #5
          Don't you dangle your pointer in my face...

          Comment

          Working...
          X