Is there a way to create a new object where the template/typename can be determined dynamically?
Suppose I have a parent class (ParentClass) with two child classes (ChildA and ChildB). I want to be able to create a new object, but won't know until runtime whether it's going to be a ChildA or ChildB. What I want is to do something like this:
But this doesn't work. The <> are not expecting a UClass* to be put between them. But I cannot figure out how to vary what goes between them. Is there a way?
Suppose I have a parent class (ParentClass) with two child classes (ChildA and ChildB). I want to be able to create a new object, but won't know until runtime whether it's going to be a ChildA or ChildB. What I want is to do something like this:
Code:
UClass* ClassToCreate; if (bSomeBool) { ClassToCreate = ChildA::StaticClass(); } else { ClassToCreate = ChildB::StaticClass(); } ParentClass* FreshObject = NewObject<ClassToCreate>();
Comment