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 created with NewObject crashing the engine?

I am trying to instantiate an UObject subclass, but I have very strange errors when I do.

 Fatal error: [File:D:\Build\++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2484] EEarlyZPass::MAX_68678 is not being constructed with either NewObject, NewNamedObject or ConstructObject.
 UE4Editor_Underwater_9207!UChunk::UChunk() [d:\projects\underwater\source\underwater\chunk.cpp:3]
 UE4Editor_Underwater_9207!UMapGeneratorComponent::CreateChunk() [d:\projects\underwater\source\underwater\mapgeneratorcomponent.cpp:97]
 UE4Editor_Underwater_9207!UMapGeneratorComponent::execGenerateMap() [d:\projects\underwater\source\underwater\mapgeneratorcomponent.h:18]

The error complains that I am not using NewObject on something called EEarlyZPass::MAX_68678 (No idea what that is).

But here is the code instantiating the object where it says it crashes:

 void UMapGeneratorComponent::CreateChunk(int x, int y)
     FString ChunkName = GetChunkName(x, y);
     UE_LOG(LogTemp, Warning, TEXT("Creating new chunk %s: [%i,%i] - %i"), *ChunkName, x, y, ChunkCreationIndex);
     UChunk* NewChunk = NewObject<UChunk>();
     Chunks.Insert(NewChunk, ChunkCreationIndex);
     ChunkIDs.Add(ChunkName, ChunkCreationIndex);

As you can see, I am using UObject.

Just in case, I made sure the constructor is empty:

 UChunk::UChunk() {

So this constructor is not calling anything, the object is just being created and stored in a TArray, nothing else happens. Yet, I get this error.

Also might be a relevant note, my class was initially a normal C++ class, which I turned into a UObject as there was no way of storing it in a TMap, then it turned out TMap didn't keep my object in memory so now I am storing it in a TArray.

I'm just trying to instantiate a class and store it in an array, but somehow this seems impossible in Unreal.

This problem also only started happening once I started trying to store the instances in a TMap/TArray. I could instantiate my class fine, but once I tried to store it it wouldn't work until I made it a UObject, and now I can't find a way that works.

Also for reference, the class definition:

 #pragma once
 #include "CoreMinimal.h"
 #include "PerlinNoiseComponent.h"
 #include "RuntimeMeshComponent.h"
 #include "FMapParameters.h"
 #include "MeshParameters.h"
 #include "Chunk.generated.h"
 UCLASS( ClassGroup=(CUSTOM) )
 class UNDERWATER_API UChunk : public UObject 
     void Generate(int ChunkID, int ChunkX, int ChunkY, FMapParameters Parameters, UPerlinNoiseComponent* Noise, URuntimeMeshComponent* RuntimeMesh);
     void GenerateVertices();
     void GenerateTriangles();
     void GenerateMesh();
     void InitMeshToCreate();
     FVector2D GetWorldPositionForGridPosition(float x, float y);
     FVector2D CalculateUV(float x, float y);
     float GetZPositionFromPerlinResult(float PerlinResult);
     int GetNoiseIndexForCoordinates(int x, int y);
     FVector GetNoiseValueAt(int x, int y);
     void SetNoiseValueAt(int x, int y, FVector value);
     bool Generated;
     int ChunkX;
     int ChunkY;
     FMapParameters Parameters;
     UPerlinNoiseComponent* Noise;
     URuntimeMeshComponent* RuntimeMesh;
     int ChunkID;
     MeshParameters MeshToCreate;
Product Version: UE 4.18
more ▼

asked Feb 13 '18 at 06:04 PM in C++ Programming

avatar image

16 3 5

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

2 answers: sort voted first

It turns out that my scene was corrupted and code wasn't properly hot reloading (which explains the weird error message that didn't quite match my code).

It's likely that my code actually did work, I just didn't know it wasn't loading in Unreal.

In the meantime, I had found an alternative to avoid using a UObject:

I wrapped my class in a USTRUCT and made my container a TMap.

This way Unreal was able to store it.

more ▼

answered Feb 17 '18 at 02:06 PM

avatar image

16 3 5

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

Well according to the stack CreateChunk is called on constructor which might not like NewObject being called on that phase. Try moving code to diffrent event as you should not run initiaion code on constructor, or else you setting defult values in arrays.

You saying that you want to use something else the UObject yet something that works with TMap, you could use struct with USTRUCT(). Structs are no different from classes in C++, even thru UE4 reflection system only allows properties in structs, you can still make functions in C++ without UFUNCTION which are not allowed in structus which many structs in UE4 does, as those function will work normally in C++,. If you want to do blueprint nodes for those you simply make static functions from blueprint library or some different UObject.

more ▼

answered Feb 14 '18 at 10:52 AM

avatar image

30.1k 903 150 1064

avatar image Nialna Feb 17 '18 at 02:04 PM

I ended up wrapping it in a struct yeah, but my problem wasn't actually coming from that.

(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