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...
}
}