RPC doesn't work on repicated UObject

So, I also need to call RPC events and found solution…

As smara mentioned above, CallRemoteFunction() returns false, but if you copy logic from AActor Component, you should get True. But there is another problem… When function calls, it reaches GetFunctionCallspace(), wich returns Local by default from UObject. You have to override it as well…

My version:

bool USpecialAction::IsSupportedForNetworking() const
{
	return true;
}

bool UMyObject::CallRemoteFunction(UFunction * Function, void * Parms, FOutParmRec * OutParms, FFrame * Stack)
{
    AActor* Owner = Cast<AActor>(GetOuter());
    if (!Owner) return false;
    UNetDriver* NetDriver = Owner->GetNetDriver();
    if (!NetDriver) return false;

    NetDriver->ProcessRemoteFunction(Owner, Function, Parms, OutParms, Stack, this);

    return true;
}

int32 UMyObject::GetFunctionCallspace(UFunction * Function, void * Parameters, FFrame * Stack)
{
    AActor* Owner = Cast<AActor>(GetOuter());
    return (Owner ? Owner->GetFunctionCallspace(Function, Parameters, Stack) : FunctionCallspace::Local);
}

NOTE, that your Outer must be an Actor, that replicates this object! If you need to call Server functions (from client), Outer should be you an Actor, wich is owned by your player controller.

1 Like