Download

Possible to load class dynamically from a string?

I have a config file that stores two arrays of strings. One array of strings holds the names of all of the loaded mutators. The other array of strings holds the mutators that are available but not currently loaded. When I start a new game, I just append “?Mutator=___” to the start command, for each mutator currently loaded.

That works fine. But not all mutators are valid for each game type. I’m trying to make a way to check that a mutator is valid. What I think I would like to do is this:

  1. Store the available mutators as strings in a config file, as I have been doing.
  2. Use a string to instantiate a new mutator object instance dynamically. We’ll call the new instance NewMutator.
  3. Create an interface with a function that will tell me which game type the mutator was designed for. if(MyMutatorInterface(NewMutator) != none) AllowedGameType = MyMutatorInterface(NewMutator).GetDesiredGameType();

I don’t know how to do step 2. Can I take a string, use it as the name of a class, and then create a new instance of that class dynamically?

Nevermind. I think I found the answer. I’m pretty sure DynamicLoadObject is what I’m looking for.

Yeah, I use DynamicLoadObject for dialogs, but the assets file must be a “seekfree” file when the game is cooked. Try that before.