I’m sorry for the unclear title. I can’t really find a concise way to phrase it.
I’ll try to come up with an example so I don’t have to explain my whole code to you.
Let’s say, for example, I have a C++ class that optimizes my shopping trip and decides which store to go to first.
For that it contains an array of structs which is an EditAnywhere UPROPERTY. Each struct represents one store which contains a few variables (FString with the name of the store, FVector for the location of the store, int with the number of items I need from that store, etc.).
Since the class uses those variables contained within the struct I want to make sure that those structs that I then add to the array in the instance of the class in the editor are all children of the same class, a kind of parent struct which defines which variables the children must contain.
When I create a struct in the Editor I can’t find an option to create a child off of it so I assume that’s not possible. If I try to create a struct class in C++ and select type “none” when I create it it doesn’t appear in the content browser.
So what would be the best practice for this? Create a blueprint of type “Actor” even though it doesn’t do anything and all I want is a set of a bunch of variables?
Or is there actually a way to create child structs?
Or is there another type in Unreal that is better suited for what I want?
I think you can use UObjects for example create: USuperShop then create child clasess e.g. UChildShopOne and UChildShopTwo etc. then in your C++ class you can have TArray<USuperShop*> where you can hold it’s child class objects too
Thank you for the help! First of all I never realized I could just create a class of type UObject instead of none. Still, I find it confusing that “None” is at the very top of the recommended classes. What would I ever use None for?
So now I have created a new class USuperShop derived from UObject and I have created Blueprints BP_Shop1 and BP_Shop2 based on USuperShop so that they have USuperShop as their parent.
In another class I have the following variable:
But when I want to add a Shop to that array in my instance in the editor none of my shops appear.
I have also tried it with c++ children of USuperShop instead of Blueprint children.
I can also not drag and drop them into the array.
What am I doing wrong here?
Edit: I guess it is because they are UObjects and not AActors so they cannot physically exist in the world. But I don’t want them to exist in the world. All I want is some kinds of sets of a couple of variables that I can plug into my instance. Of course I could use actors but wouldn’t that be overkill? A class that only contains a few variables and doesn’t actually do anything sounds like exactly the right thing to choose an UObject for instead of an AActor.
Edit2: I just tried it again with Actors and it still doesn’t work. Still nothing appears in the drop down menu when I want to add something to the array.
Edit3: Ok, so instead of TArray<ASuperShop>* Shops;
I had to write TArray<TSubclassOf<ASuperShop>> Shops;
because I am not referencing an instance of that class but rather the class itself.
C++ is still a big riddle to me.
I guess this way it might also work with UObjects.