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

**URL:** <https://forums.unrealengine.com/t/using-base-c-classes-vs-deriving-from-uobjects-and-working-with-tarrays/138733>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 23, 2020, 12:36am UTC](https://forums.unrealengine.com/t/using-base-c-classes-vs-deriving-from-uobjects-and-working-with-tarrays/138733 "2020-02-23T00:36:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cheesy11623](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cheesy11623](https://forums.unrealengine.com/u/Cheesy11623)\
**Post date:** [February 23, 2020, 12:36am UTC](https://forums.unrealengine.com/t/using-base-c-classes-vs-deriving-from-uobjects-and-working-with-tarrays/138733/1 "2020-02-23T00:36:54Z")

</div>

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

```auto

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

---

<div class="post-metadata">

**Author:** ![KelbyVP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kelbyvp/32/261024_2.png) [@KelbyVP](https://forums.unrealengine.com/u/KelbyVP)\
**Post date:** [February 23, 2020, 9:01am UTC](https://forums.unrealengine.com/t/using-base-c-classes-vs-deriving-from-uobjects-and-working-with-tarrays/138733/2 "2020-02-23T09:01:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [February 23, 2020, 12:15pm UTC](https://forums.unrealengine.com/t/using-base-c-classes-vs-deriving-from-uobjects-and-working-with-tarrays/138733/3 "2020-02-23T12:15:04Z")

</div>

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.
