Is it possible to assemble a list of classes of a type at runtime? (BP or C++)
I am working on a system to spawn random actors and thus need a random class. I would like to avoid making a array/map/etc of every class as they are created because it's fairly easy to make mistakes with (e.g., forgetting to add one.) I had the idea to use a program to generate a table by scanning all the files, but that would rely on being able to get a class by name which I couldn't find anything about being able to do it.
Edit for some clarity of what I am trying to accomplish:
Something similar to this, but instead of map names it provides class types.
I am creating an endless side scrolling shooter that spawns a random tile as you move forward. I plan on having many different types of tiles and as such I will have many blueprints subclassing e.g. TileBase. As far as I can find the only way to get a random class to spawn is by creating an array of the type of tile classes - thus every time I make a new tile I need to manually add a new entry into the array (this is, for example, how it's accomplished in the Infinite Runner tutorial.) There are ways to optimize this, of course, but that's beside the point.
My current solution is to use a data table. It has the advantage of being able to pair the class with a gameplay tag container to more easily filter the tiles to randomly choose from. As stated before, however, it opens up the issue of forgetting to add new entries to the table.
Each class has corresponding UClass object in memory, so all you need to do is iterate theu them using TObjectIterator, filter them and add matching once to array or whatever you want
Problem is it is expensive process even heavier then actor iteration with Get All Actors of Class, so you should do this once, in beginplay for example
In blueprint it impossible... i think? if you can iterate objects you should be able to. Generly it would be better if you do this in C++ for performance and you can also re use array created in C++ in blueprint.
Follow this question
Once you sign in you will be able to subscribe for any updates here