Trying to get a function working which will allow me to instantiate a class chosen by the designer in blueprint.
The code currently is:
UEffectBase* UCodeFunctionLibrary::CreateEffect(TSubclassOf<UEffectBase> EffectClass, float magnitude, FVector direction)
{
UEffectBase* CreatedEffect = NewObject<UEffectBase>(EffectClass);
CreatedEffect->initializeEffect(magnitude, direction);
return CreatedEffect;
}
The problem is that it always creates a UEffectBase - never what EffectClass actually is handed in as (ie. damage, knockback etc.). I’m assuming this is because I’m explicitly stating the type as UEffectBase in the NewObject call - but any attempt to put a variable or TSubClassOf in, ie. NewObject
- just causes compile errors.
I’m sure this is possible, what is the syntax to get NewObject to instantiate a type of TSubObject?