Download

Help with UObject definitions and Management

Hello,

I’m wanting to write a simple class that will contain a nested amount of simple node information. What I want to achieve in memory can be seen below along with the declarations.

EXAMPLE MEMORY

Dictionary Object
Children Static Array
[0] NULL
[1] NULL
[2] <Node Object>
Complete Property : true
Children Property
[INDENT][0] NULL
[1] NULL
[2] NULL
[3] <Node Object>
[INDENT]Complete Property: false
Children Property NULL (NOT INSTANTIATED)
[4][/INDENT] NULL[/INDENT]
[3] NULL
[4] NULL

CLASS DEFINITIONS

Dictionary Class
{
STATIC ARRAY OF Node POINTERS Children;
}

Node Class
{
bool Complete;
STATIC ARRAY OF Node POINTERS Children;
}

My first attempt was to try and do it using all standard c++ declarations. I soon realized that my objects were being removed from under me. I now realize I probably need to use UObjects, UStructures & UPROPERTIES to make sure my objects are being properly maintained. My problem is that I’m still getting used to C++ again as I’ve been using c# for many years now.

I would like my Dictionary class to be created when the GameMode is created. It shouldn’t be deleted unless the GameMode is destroyed. Is it right to assume I should declare the Dictionary property as UPROPERTY so it will not be garbage collected? Will it automatically make the GameMode the root component or do I need to pass in (this) when I create it within the GameMode?

As far as the Dictionary class itself I’m assuming i should make it a UCLASS but I was wondering if a USTRUCT would be a better solution.

As far as the Node class I was wondering the same thing. Should it be a UCLASS or USTRUCT?

Lastly, when I create the Children they will be owned by the class that created them. I won’t have any other classes pointing to them in any way. I also know that I will create exactly 5 elements, however, I want the ability to not create any to save in memory costs. Will a TStaticArray allow this option? Also, my array would have to contain a pointer since each element may or may not be instantiated. Is this possible to point it to a USTRUCT* or does this requirement force my Node to become a UOBJECT*?

All of these properties do NOT have to be exposed to the editor in any way. I have other methods that are exposed that will utilize the data in memory and return simple booleans.

I appreciate any help you can give as I’m just trying to get my feet wet.

-jv