Hello,
I am making status/ailment system for my game. I have an actor component that will hold and manage status effects on the unit, and I have each status be a UObject derived class, like:
UBaseStatus : public UObject
UStatusKnockback : public UBaseStatus
And there is a virtual function OnApply()
in the base class that I override in the child knockback class.
I have an enum that holds the types of statuses EStatusType
In the header of the component I have a map of the status classes, where I set in the editor what class goes to what status type:
UPROPERTY(EditAnywhere, BlueprintReadOnly)
TMap<EStatusType, TSubclassOf<UBaseStatus>> StatusLookup;
Then in the cpp of the component I create a status like:
UBaseStatus* NewStatus = NewObject<UBaseStatus>(this, KnockbackClass);
NewStatus->OnApply();
The result is that instead of the OnApply
on the UStatusKnockback
class, I’m getting the OnApply in the UBaseStatus
class called.
I have tried calling the new object function is these ways:
UBaseStatus* NewStatus = NewObject<UBaseStatus>(this, KnockbackClass->StaticClass());
UBaseStatus* NewStatus = NewObject<UBaseStatus>(GetTransientPackage(), KnockbackClass);
The first one results in a crash with the error of Assertion failed: Child->IsChildOf(Parent)
And the second one gives the same result as the initial problem.
Thank you in advance and kind regards,
Svetlin