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"

How to derive from UObject and instantiate at runtime from C++?

I have the following class:

 UCLASS(BlueprintType, Blueprintable)
 class MYPROJECT_API UFloorplanGraph : public UObject
     UFloorplanGraph(const FObjectInitializer& ObjectInitializer){}
     // Some Properties ...

     virtual void Serialize(FArchive &Ar) override;

At runtime, I am executing this piece of code:

 UE_LOG(LogTemp, Log, TEXT("We detected an object and create it."));
 Ref = NewObject<UObject>(DetectedClass);
 UE_LOG(LogTemp, Log, TEXT("This point is never reached."));

In this context, detected class equals UFloorplanGraph::StaticClass(). But I get an error with the following message.

 Class which was marked abstract was trying to be loaded.  It will be nulled out on save. None Object

As far as I understand I can not create an instance of UFloorplanGraph because it is abstract.

Question: What do I need to do to make it not abstract and instantiable?

This is a more detailed excerpt of the log file:

 [2016.08.23-15.13.09:107][ 77]LogTemp: We detected a class: /Script/AeonDevelopment.FloorplanGraph
 [2016.08.23-15.13.09:107][ 77]LogTemp: We detected an object and create it.
 [2016.08.23-15.13.09:107][ 77]LogUObjectGlobals:Warning: Class which was marked abstract was trying to be loaded.  It will be nulled out on save. None Object
 [2016.08.23-15.13.09:107][ 77]LogOutputDevice:Warning: 
 Script Stack:
 [2016.08.23-15.13.09:751][ 77]LogStats: FPlatformStackWalk::StackWalkAndDump -  0.644 s
 [2016.08.23-15.13.09:751][ 77]LogOutputDevice:Error: === Handled ensure: ===
 [2016.08.23-15.13.09:751][ 77]LogOutputDevice:Error: 
 [2016.08.23-15.13.09:751][ 77]LogOutputDevice:Error: Ensure condition failed: false [File:D:\Build\++UE4+Release-4.13+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2139]
 [2016.08.23-15.13.09:751][ 77]LogOutputDevice:Error: Class which was marked abstract was trying to be loaded.  It will be nulled out on save. None Object
 [2016.08.23-15.13.09:752][ 77]LogOutputDevice:Error: Stack: 
 [2016.08.23-15.13.09:752][ 77]LogOutputDevice:Error: UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build\++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:183]

And the error message keeps going like this... Afterwards, I immediately get an access violation error (trying to access null).

Any help is welcome!

Product Version: UE 4.13 Preview
more ▼

asked Aug 23 '16 at 03:41 PM in C++ Programming

avatar image

151 5 10 14

avatar image Doug E ♦♦ STAFF Aug 23 '16 at 05:45 PM

Hey rYuxq-

Are you trying to add an instance of FloorplanGraph to the level? If this is the case, can you try inheriting the class from AActor instead of UObject? Are you adding the log messages in the BeingPlay function of the FloorplanGraph class or in another file? Are you getting the reported error in Visual Studio or inside the editor?

avatar image rYuxq Aug 24 '16 at 09:22 AM

Hey Doug! I am calling a blueprint function library method (which is implemented in c++) from the level blueprint and which is effectively executing those 3 lines of code above. The log messages are print from this chain of function calls (in c++). The error message was an excerpt of the log file of the editor, since the editor crashes. Also,I am not sure if I am trying do add it to the level (or rather, I don't think I know what you mean) All i do is have a reference from the level blueprint to it, which should be fine. I am neither trying to spawn or place it anywhere, which is why I thought uobject would be good.

avatar image rYuxq Aug 24 '16 at 09:29 AM

Ahh, maybe I should add that calling the "construct object" node from the level blueprint works perfectly fine. This error happens only when I call new object the way I described above. Also, there are two errors in total. One which is a failed (but handled) ensure and before returning from the new object function call, I also get a critical error (an access violation error)

avatar image Doug E ♦♦ STAFF Aug 24 '16 at 02:10 PM

You mentioned a crash, can you explain when the crash occurs? Please also include the callstack and log file from the crash.

For the UObject itself, you should be able to use ConstructObject at runtime. Can you also try replacing "DetectedClass" with UFloorplanGraph::StaticClass() directly to see if that helps?

avatar image rYuxq Aug 24 '16 at 06:17 PM

Can you recommend me a site to upload the logfile and the callstack to? I think just posting it here would be too cumbersome for the reader.

Also, i will try passing UFloorplanGraph::Staticclass() directly once I am back home and compose a proper response.

avatar image Doug E ♦♦ STAFF Aug 24 '16 at 06:32 PM

The callstack and log files should both be able to be saved as .txt files which can then be uploaded as attachments or zipped together before adding them.

avatar image rYuxq Aug 24 '16 at 09:32 PM

Actually, never mind. The crash happened because I used "NewObject" wrong. I used "DetectedClass" as Outer, even though I meant to use it as the class to create. DetectedClass as to be the second argument that I pass. Which leads me to another question. Is it save to use "GetWorld()" as Outer?

Actually, the code that is involved with all this is meant to deserialize an UObject from a file. Which leads me to a more important question: How should I deal with parent/outer references when I want to serialize a UObject? And how should I deserialize it again? I assume that this is a common question that comes with serialization..

avatar image rYuxq Aug 25 '16 at 04:17 PM

thank you for the support!

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

1 answer: sort voted first

I have been using the NewObject function wrong.

 Ref = NewObject<UObject>(Outer, DetectedClass);

is the way to go. I didnt provide an outer, thinking it was not necessary.

more ▼

answered Aug 25 '16 at 04:17 PM

avatar image

151 5 10 14

(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