Dynamically creating classes

Is it possible to dynamically create a class or struct at runtime?

Suppose I have a small base class LEV_ParamsBase;

and I derive classes



When I load in a level, I dont want to have a thousand #include, nor do I want a huge switch statement of all my classes

What I would like to do is something like

FName LevelName = LEV_CurrentLevelName;
LEV_ParamsBase* TheLevelParameters = NewObject(LevelName::StaticClass());

Maybe factory/factory method?

It’s hard to say without more details.
What is LEV_ParamsBase and why you need nearly ten thousand derivatives classes? What is a diff for example between LEV_1000 and LEV_1001?

when I open a new level, I want to load in the level parameters

most will be defined in a base class and will be the same across 10000 classes,

the parameters that are different, I want to be able to override in the child classes.

So I need to be able to dynamically create the object based on a level number integer.

Still don’t know what you want to achieve. Provide some snippet code.

This seems like a perfect use case for data tables.

1 Like

Thats what I did…

I adapted my asset preloader to handle datatables

Now I have all my level data in a spreadsheet, export as csv, and import into the editor as asset

My Level Controller, now gets its Level Parameters from the Datatable Controller…

Now I see possibility for storing all my asset references in a spreadsheet and importing those into my Preloaders via the Datatable, rather than hard coding…nice!

As Im under development and parameters are add, does anyone know how to reparent a datatable when it looses its row structure, sometimes this changes in the c++ file and I have to recreate the datatable from scratch because it loses its hotreload, sometimes not.

Are you saying you’re using the compile button in editor?