Best approach for RPC call from Actor

I’m fairly new to UE4 and wanted to try to get my head around how best to handle the following situation:

I have a Blueprint with a custom AActor subclass (MySwitch) as it’s base class. The Blueprint has been dragged into a level, and acts as a switch. When players approach it and press the E key, it triggers a MySwitch::OnUse method. What I’m looking for clarity on is how to handle letting the server know that the switch’s OnUse was triggered when a client is the one responsible for “using it”. I was looking to do this via an RPC, but my understanding was that the calling client must own the actor (which I believe isn’t true in this case). So what’s the best way of handling this? Should I get a reference to the local player’s character (which is owned by the client) and have it send the RPC?


void MySwitch::OnUse_Implementation()
{
    Super::OnUse_Implementation();
    
    MyGameMode* gameMode = (MyGameMode*)GetWorld()->GetAuthGameMode();
    if(gameMode)
    {
        // We've got an instance of the Game Mode, so this must be the server...
    }
    else
    {
    	// Looks like we're the client, so we need to figure out a way of contacting the server...
    }
}

I use the way you described, doing the RPC through the player character. I have an IInteractable interface with an OnUse function. In my setup when pressing E the client traces for an IInteractable actor. If he finds one he calls a server RPC on the character, ServerAttemptUse(IInteractable*) which then calls the interface OnUse server-side but only if some checks like distance are passed.

according to ShooterGame demo:



void AShooterWeapon::SetOwningPawn(AShooterCharacter* NewOwner)
{
	if (MyPawn != NewOwner)
	{
		Instigator = NewOwner;
		MyPawn = NewOwner;
		// net owner for RPC calls
		SetOwner(NewOwner);
	}	
}