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.
The error complains that I am not using NewObject on something called
But here is the code instantiating the object where it says it crashes:
As you can see, I am using UObject.
Just in case, I made sure the constructor is empty:
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:
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
I wrapped my class in a
This way Unreal was able to store it.
answered Feb 17 '18 at 02:06 PM
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.
answered Feb 14 '18 at 10:52 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here