Hi!
I created an interface to allow the player interact with an actor when it is close enough. This is the code for that actor.
Header:
private:
TObjectPtr<class ILeverInteract> PlayerCharacter;
Code:
void MyClass::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
PlayerCharacter = Cast<ILeverInteract>(OtherActor);
if (PlayerCharacter)
{
PlayerCharacter->LeverInteractDelegate.AddUniqueDynamic(...);
}
}
void MyClass::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (PlayerCharacter)
{
PlayerCharacter->LeverInteractDelegate.RemoveDynamic(...);
}
}
My question is: how do I have to declare the PlayerCharacter
variable?
I have used TObjectPtr
, but I don’t know if it is the best choice to declare it.
Thanks!