x

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"

Clarification about GC and NewObject<>

I have a plugin module where the implementation class is derived from custom derivation of IModuleInterface. The module loads fine and is accessible. Inside the module implementation I have a private regular C++ pointer (not decorated with UPROPERTY because after all this class is a module class and not an UObject) to a custom UObject. Inside StartupModule I allocate an instance of that object using NewObject<>.

Is this sufficient for keeping said private UObject alive? NewObject<> assigns a default Outer object, no? And so isn't that good enough to keep it alive from the GC? I test the persistence by calling GetWorld()->ForceGarbageCollection(true) inside my custom PlayerController in the main game module repeatedly through a triggered UFUNCTION, and the UObject in question seems to stay accessible. I am just getting lucky or is what I am doing legit?

Product Version: Not Selected
Tags:
more ▼

asked Apr 15 '15 at 03:33 AM in C++ Programming

avatar image

dekrat
42 9 11 13

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

1 answer: sort voted first

As I understand things that shouldn't be safe, I didn't think that the outer contributed to reference counting by default. So I'm surprised it's working. Anyway, to be safe, just call AddToRoot() on your object immediately after creating it. This will make sure it remains referenced for the duration your program runs.

more ▼

answered Apr 15 '15 at 06:48 AM

avatar image

kamrann
2.1k 83 33 119

avatar image dekrat Apr 16 '15 at 12:53 AM

Got it. Will do, although I hope one day UE4 memory rules and structure will be clarified further.

(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