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
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
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.
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
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.