I’ve got an interface working that can be used by my class PlayerCharacter to call functions in other classes. What I’d like to be able to do is, on a function call, pass along a reference to PlayerCharacter so that when another class gets that function call, it knows which player called it and I can assign it a reference to the player currently interacting with it (this will be extremely useful for me for a lot of things down the road).
I imagine this should look something like this (don’t mind any minor typos, this isn’t my actual code):
// Interface.h
UFUNCTION(*some parameters*)
void Interact(AActor* RefToPlayerCharacter);
//-------------------------------------------
// PlayerCharacter.cpp
AActor* RefToPlayerCharacter = [*Somehow getting a reference to this player character*];
IInterface::void Execute_Interact(RefToPlayerCharacter);
//-------------------------------------------
//InteractableObject.h
UPROPERTY(*some parameters*)
AActor* OwningPlayerCharacter;
//InteractableObject.cpp
void AInteractableObject::Interact_Implementation(AActor* RefToPlayerCharacter)
{
OwningPlayerCharacter = RefToPlayerCharacter;
}
The problem is that pesky “[Somehow getting a reference to this player character]” part. I don’t know what I should use there. GetOwner() returns an AActor* object type, but as I don’t know what exactly we’re getting the owner of (the root component? This instance of this actor? The actor as a whole?), I don’t know if this owner in this case would give me the current instance of PlayerCharacter or return something I don’t want. I’ve also seen some suggestion online to use “this->” beforehand (i.e. “this->GetOwner()”), but I don’t know if that’s an appropriate use in this case. Or if I should be using something else entirely.
Any help/insight would be hugely appreciated!