Creating an Effect (C++)
Effects now use a single-class model.
Create one class derived from UEDInteractionEffect and override the lifecycle you need:
OnStart_Implementation()OnTick_Implementation(float DeltaSeconds)OnFinish_Implementation()
Example:
#include "Effects/EDInteractionEffect.h"
#include "Components/PrimitiveComponent.h"
#include "MyEffect.generated.h"
UCLASS()
class UMyEffect : public UEDInteractionEffect
{
GENERATED_BODY()
public:
UMyEffect()
{
Channel = TEXT("MyEffect");
}
protected:
virtual void OnStart_Implementation() override
{
Super::OnStart_Implementation();
if (UPrimitiveComponent* Target = GetTargetComponent())
{
Target->AddLocalOffset(FVector(0.f, 0.f, 2.f));
}
}
virtual void OnTick_Implementation(float DeltaSeconds) override
{
Super::OnTick_Implementation(DeltaSeconds);
if (GetElapsedSeconds() >= 0.2f)
{
Finish();
}
}
virtual void OnFinish_Implementation() override
{
if (UPrimitiveComponent* Target = GetTargetComponent())
{
Target->AddLocalOffset(FVector(0.f, 0.f, -2.f));
}
Super::OnFinish_Implementation();
}
};
Useful notes:
- The same class is used for authoring and runtime spawning.
- Default property values on your class are copied into each runtime effect object.
GetEffectContext()gives you the full interaction context.GetPreferredEffectLocation()andGetPreferredEffectNormal()are good defaults when your effect wants a hit-driven point in space.- Call
Finish()when your effect is done.
Then add UMyEffect to the arrays in UEDInteractionEffectsComponent (or to foliage effect configuration where applicable).