Using base c++ classes vs deriving from UObjects and working with TArrays

Hi,

Apologies if this has already been asked before, but I couldn’t find an answer that made sense to me.

My specific question is: Is there a portable way to have a collection of object that do not derive from UObject? And the more general question is should all c++ classes inherit from UObject (or any derived classes of UObject). If not, what are some guidelines around when you should/shouldn’t derive from UObject?

As background, I am playing around with a hex board game, and wanted to store the hex coordinates in a class: HexCoordinate. I initially made this a basic c++ class (not inheriting from anything) but then I wanted to be able to store several coordinates in a container, e.g. TArray. But when I try and do this it complains


Error    C2039    'StaticClass': is not a member of 'TArray<HexCoordinate,FDefaultAllocator>

I can’t see much documentation about this, but I thought it was that TArray can only have objects that inherit from UObject.

But if I convert it to a UObject, I have to use pointers and use NewObject and can’t use constructors and … Which seems really annoying when I just want to create a lightweight object to store a few uint32’s. Is there a way around having to use this?

Hope this makes sense, thanks in advance

Not sure whether you can make a Tarray out of a custom class that is not a child of UObject. However, I regularly do what you’re trying to do by creating a custom struct that contains int32s and then make a TArray out of the struct.

TArrays can contain anything you want - whether it be a type, a native CPP class or a UObject.

Judging by that error you are trying to call StaticClass() on TArray which makes no sense - post the code you have written and we can point out the error.