Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[Question] UObject Pointer References - in containers

Hello Everyone,

Today is a core engine question, that may have already been asked, but I believe I am appending to.

In https://answers.unrealengine.com/questions/4485/question-uobject-pointer-references.html an explanation is established but no real documentation is referenced. Also I am curious as to the TArray implementation and if what is said in the mentioned post is still true. So...
How do TArray arrays benefit from being marked as UPROPERTY? Also, does the same behavior apply to other containers, like TSet and TMap?


Product Version: UE 4.19
more ▼

asked Jun 18 '18 at 10:16 PM in C++ Programming

avatar image

1.1k 41 33 76

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Yes to all. Benefits Planty. Docs avaivable. TSet & TMap currently can´t be replicated and maybe a couple minor things not fleshed out regarding the UPROPERTY() Macro but generaly speaking works the same as TArray.


You can find more Documentation regarding all sorts of Topics including Garbage Collection.

Have Fun =)

more ▼

answered Jun 19 '18 at 01:07 AM

avatar image

7k 143 28 172

avatar image Spiris Jun 19 '18 at 03:46 AM

Good information, I was mostly curious about the tidbit on UObject* garbage collection and memory management, as in the original question it mentions that TArrays don't free memory on their own, even as a UPROPERTY(), and may not really benefit from being marked as such when it comes to memory management. So unless I want to get the other UPROPERTY() benefits for my TArray of UObject*, there is no reason to mark them as such.
Part of me wants to think that in the past four years this could have changed, and wants to know if it has, so I can make the right decisions going forward.

avatar image Spiris Jun 19 '18 at 05:10 AM

So it looks like I misread a bit of it, and misunderstood a bit more. The truth of it is all mostly laid out in this doc:

It makes note that unreal engine containers TMap, TSet, TArray, etc all behave in the way mentioned in the original question. The object pointers in them of course can go null via destruction, so storing nullptrs and managing the memory that the object pointers take up in the containers is up to the user, but the objects themselves are handled by the engine as they no longer have references. At least that is how I am understanding it.

My old rule of thumb was if it has anything to do with UObjects, its best to keep it as a UPROPERTY, but going ahead I feel like I can make much better decisions on this now.

This seems like a good enough answer for me, if there is something I missed or needs more clarity, please clarify, either way, thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question