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"

Why is my UObject being GC'd?

Hi

So i am trying to instantiate a UObject at runtime using NewObject like so:

 if(Group->PatternClass)
     Group->Pattern = NewObject<ULightingPattern>(GetTransientPackage(), Group->PatternClass);

I am marking the variable as a UPROPERTY, so as i understand it, the garbage collector should know when i am referencing this UObject:

 UPROPERTY()
 ULightingPattern* Pattern;

The problem i have is after a certain amount of time, this UObject is being destroyed or marked as invalid and i get a crash at this point:

 // Update visuals
 if (!IsValid(Group->Pattern))
     continue; // Only skip this group

I cannot see any reason why this is. I have checked to make sure it is definitely the GC that is destroying the object, by creating the object with the MarkAsRootSet flag, which appears to fix this issue, but then the editor crashes when ever i try and exit the game as it cannot destroy the object.

If it helps at all, the UObject is being reference from a USTRUCT which is referenced by value from a UActorComponent like so:

 USTRUCT(BlueprintType)
 struct FLightingGroup
 {
     GENERATED_BODY()

     ...

     UPROPERTY()
     ULightingPattern* Pattern;
 }


 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class POLICE1013_TECH1_API UEmergencyLightingComponent : public UActorComponent
 {
     GENERATED_BODY()

 public:

 UPROPERTY(Category = "Settings", EditDefaultsOnly)
 TArray<FLightingGroup> LightingGroups;



Product Version: UE 4.14
Tags:
more ▼

asked Feb 10 '17 at 12:37 AM in C++ Programming

avatar image

KieranChandler
128 10 17 20

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

1 answer: sort voted first

It seems switching between GetTransientPackage() and this has fixed the issue

more ▼

answered Feb 10 '17 at 01:27 AM

avatar image

KieranChandler
128 10 17 20

(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