Hey guys,
I have got a class called AMazeRoom (: AActor), and several Blueprints inheriting from that class. Now I created a TArray > mazeRooms, and filled it with the Blueprint Classes.
Now I want to Spawn Actors from those classes, but I can’t find a way to do it, since SpawnActor(mazeRooms[0]::StaticClass()) and similar doesn’t work.
How can I do this?
What do you mean it doesn’t work? It should work fine if you pass it a UClass*
When I do
AMazeRoom* room = (AMazeRoom*)()->SpawnActor(TAdifferentRooms[roomIndex]->StaticClass());
the resulting room is a nullptr, and I have no Idea why.
TAdifferentRooms is my TArray of subclasses of AMazeRoom
Make a array:
TArray<SubclassOf<AMazeRoom>>
You could use UClass* but this will limit selection to subclasses of AMazeRoom. Fill the array with classes in blueprint and if you do that spawn in blueprint, in C++ you can do it by
SpawnActor(mazeRooms[0]);
As array should be filled with UClasses
Thanks! I just had to remove the mazeRooms[0]->StaticClass(), now it works