How can I create a new object from a pointer?

I cant seem to create a new object from a nested pointer for my plugin. My code is setup like so: I create a query object, the query object has a model property. I need to return an array of models. Currently I’m stuck creating an array of models all pointing to the same thing. How would I create a new instance of the model in a for loop?

UDatabaseCommunicatorModel is its own .cpp, and Model is its own .cpp
Both are UObjects

Code Below:

TArray UDatabaseCommunicatorQuery::GetQueryResults(UDatabaseCommunicatorQuery* Query)

{

TArray<UDatabaseCommunicatorModel*> ModelArray;

//For Loop{
    UDatabaseCommunicatorModel Model = *Query->QueryModel;
    //Add the new Model object to the array
}

return ModelArray;

}
This code does not compile because VS 2013 is stating that GENERATED_UCLASS_BODY() is inaccessible in the Model .h
Everything is set to public

Thanks for any help

Hi Stunt ,

Can you please provide me with your Model.h and Model.cpp files? If GENERATED_UCLASS_BODY() is inaccessible, the problem may be somewhere outside of the function you provided.

Files are attached thx for the help.

This most likely isn’t related to the problem but since 4.6, GENERATED_UCLASS_BODY() has been replaced with GENERATED_BODY, just FYI.

I should have been more clear when asking but can you send me the actual code files themselves? It would also help to have all of them as you are including some other files. This way I can put them right into a project and run them through the compiler and get the errors as I attempt to identify the issue.

I attached the query header and cpp. Notice the intellisense on line 104 in the query cpp where i’m trying to create a new Model. Im new to C++. I’m actually a .net developer trying to create a ODBC plugin for unreal. C# to C++ is a pain lol. Thx again for the help man.

It’s not replaced, it does different things. GENERATED_UCLASS_BODY() when you need the Objectinitializer in your constructor, GENERATED_BODY when you want to define your class constructor yourself…

GENERATED_UCLASS_BODY() macro ends in public scope
GENERATED_BODY macro ends in private

And I made the change to GENERATED_BODY() in all my plugin classes

Ah, thank you for that information. I was under the assumption it was simply replaced.

I believe I may of pinpointed the issue. The line you pointed out that has the intellisense error is a little off. The correct way should be:

UDatabaseCommunicatorModel *Model = UDatabaseCommunicatorModel();

Or if that doesn’t work:

UDatabaseCommunicatorModel *Model = new UDatabaseCommunicatorModel();

This should create a UDatabaseCommunicatorModel pointer to a new UDatabaseCommunicatorModel object. You could also put a value in the parentheses if you wish to initialize the new object. This is how it would be done in normal C++ (I’m not exactly sure how friendly UE4 is with the ‘new’ operator). I’m not sure exactly how this will react to UProperties either.

Hopefully this will help, if not, please let me know.

Considering this has something to do with GENERATED_BODY not being public, I created a new post GENERATED_BODY() is inaccessible - Plugins - Epic Developer Community Forums

Go Fish :frowning:

UDatabaseCommunicatorModel *Model = NewObject(Query->QueryModel);

will compile, but my Model has an array of columns that is not being copied to the new Model

Have you tried ConstructObject? (Not sure if this will help though.)

Or alternatively create your own constructor to add values as needed.

UDatabaseCommunicatorModel(const FObjectInitializer& ObjectInitializer);

This is what i was looking for:

UDatabaseCommunicatorModel* Model = Cast(Query->QueryModel);

Normal C++ casting doesnt work on UObjects