Setting UObject* to UObject() causes conversion issues

So I have this line:
UObject* CharacterObject = UObject();
But it wont allow it because UObject() is type UObject and UObject* Is type… Well, UObject*.

I don’t know of any other way to declare a new UObject with a pointer. I tried UObject*() but it doesnt work.

No one knows the answer?

Hello AWPlays49,

you should be using factory methods for allocating and constructing objects the inherit from UObject. Please see this page for some possibilities: UObject Instance Creation | Unreal Engine Documentation

Except for the fact that UObjects are constructed using factory methods, your code would be correct syntactically if it were:
UObject CharacterObject();

Remember this allocates the object on the current function’s stack; as UObjects are memory-managed however, this is not possible.


You have to create a new UObject with NewObject< UObject >(this)

Thank you for your in-depth answer! Very helpful. Much appreciated!!!