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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

[BUG] UObject Constructors cause Crashing that was not present before

I have this class called UMyObject:

in .h

 #include "Object.h"
 #include "MyObject.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class MONOCHROME_API UMyObject : public UObject
 {
     GENERATED_BODY()
 public:
         UMyObject();
     
     
 };

In .cpp

 #include "ProjectName.h"
 #include "MyObject.h"
 
 
 UMyObject::UMyObject(){}


In 4.6 I could easily instantiate this class by calling in another part of the code:

 UMyObject* TestObject = new UMyObject();

But now in 4.7.1 it seems I can no longer.

I get an exception error, breaking takes me here:

 UObject::UObject()
 {
     FObjectInitializer* ObjectInitializerPtr = FTlsObjectInitializers::Top();
     UE_CLOG(!ObjectInitializerPtr, LogUObjectGlobals, Fatal, TEXT("%s is not being constructed with either NewObject, NewNamedObject or ConstructObject."), *GetName());
     FObjectInitializer& ObjectInitializer = *ObjectInitializerPtr;
     check(!ObjectInitializer.Obj || ObjectInitializer.Obj == this);
     const_cast<FObjectInitializer&>(ObjectInitializer).Obj = this;
     const_cast<FObjectInitializer&>(ObjectInitializer).FinalizeSubobjectClassInitialization();
 }

with this line highlighted:

 check(!ObjectInitializer.Obj || ObjectInitializer.Obj == this);

Is this as intended? Because judging by 4.7's notes, and 4.6's notes, I'm understanding that parameter-less constructors anywhere was an intended feature, and I was able to construct UObjects this manner in 4.6.

Any help would be greatly appreciated.

Product Version: Not Selected
Tags:
more ▼

asked Mar 04 '15 at 10:04 AM in Bug Reports

avatar image

TheCompScientist
25 2 3 8

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

1 answer: sort voted first

Yes, this is intended. Right now you can't use "new" to create a UObject. You need to use one of mentioned functions to do this.

Because judging by 4.7's notes, and 4.6's notes, I'm understanding that parameter-less constructors anywhere was an intended feature, and I was able to construct UObjects this manner in 4.6.

You still can do it using NewObject, as it have all optional parameters. You only need to provide a UObject's class as template parameter.

Thanks, Jarek

more ▼

answered Mar 04 '15 at 10:20 AM

avatar image TheCompScientist Mar 04 '15 at 10:59 AM

Wow! Thanks for the quick response (really was not expecting it that soon)

Now I understand completely what the error message meant.

 UMyObject* TestObject = NewObject<UMyObject>();

(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