# RPC doesn't work on repicated UObject

**URL:** <https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736>\
**Category:** Community & Industry Discussion\
**Tags:** uobject, Replication, rpc, unreal-engine, question, calls\
**Created:** [June 14, 2016, 11:56am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736 "2016-06-14T11:56:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sashka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sashka](https://forums.unrealengine.com/u/Sashka)\
**Post date:** [June 14, 2016, 11:56am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/1 "2016-06-14T11:56:21Z")

</div>

I’ve set up my UObject derived class properly (like recomended [here](https://wiki.unrealengine.com/Replication#Advanced:_Generic_replication_of_Actor_Subobjects)). And property replication works good, BUT I can’t call RPC on this object. On server side I’ve tried to call method marked as `UFUNCTION(NetMulticast, Reliable)`. And it didn’t work.  
When I rederived this my class from `UActorComponent` (instead of simple `UObject` with setted up replication), this method started work.  
What have I missed? Why didn’t it work?

---

<div class="post-metadata">

**Author:** ![smara](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smara](https://forums.unrealengine.com/u/smara)\
**Post date:** [June 24, 2016, 10:23pm UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/2 "2016-06-24T22:23:04Z")

</div>

Hi there,

I am researching this topic as well and also implemented your referenced link.  
I’ve looked right into the engine code and interestingly enough “CallRemoteFunction” of UObject simply returns false, while Actor and ActorComponent are implementing the function like this:

```
bool UActorComponent::CallRemoteFunction( UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack )
{
	if (AActor* MyOwner = GetOwner())
	{
		UNetDriver* NetDriver = MyOwner->GetNetDriver();
		if (NetDriver)
		{
			NetDriver->ProcessRemoteFunction(MyOwner, Function, Parameters, OutParms, Stack, this);
			return true;
		}
	}

	return false;
}

```

First of all, I do not really know how RPCs are exactly created from the written code. But since UObject is not able to do RPCs, while Actor and ActorComponents can and these two inherit from UObject, there must be some function(s) which override(s) something from UObject to allow the known behaviour of RPCs.

As you can see there is a need of an Owner and further along if you want to differ your Role between ROLE\_Authority or ROLE\_… you will realize that UObject does not have a role. Problem is UObject does neither contain Owner nor a Role.

---

<div class="post-metadata">

**Author:** ![Sashka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sashka](https://forums.unrealengine.com/u/Sashka)\
**Post date:** [July 8, 2016, 12:26pm UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/3 "2016-07-08T12:26:49Z")

</div>

Thank you. Please, make your answer realy “answer” to let me accept it.

---

<div class="post-metadata">

**Author:** ![smara](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smara](https://forums.unrealengine.com/u/smara)\
**Post date:** [July 10, 2016, 6:16am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/4 "2016-07-10T06:16:39Z")

</div>

Changed it.

---

<div class="post-metadata">

**Author:** ![Sir\_Rogers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sir\_Rogers](https://forums.unrealengine.com/u/Sir_Rogers)\
**Post date:** [July 29, 2016, 7:03pm UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/5 "2016-07-29T19:03:43Z")

</div>

Erm since the “answer” is only an answer to your question as to why it doesn´t work, assuming that you would actually like to know how you can make it work and have a proper visual demonstration of what works and what doesn´t work as a cheatsheet from the actual documentation, see here: [http://prntscr.com/bz6o5l](http://prntscr.com/bz6o5l)

Reference: [RPCs | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Actors/RPCs/index.html)

So to sum up - if you want this to work, you don´t use NetMulticast - but use Server.

---

<div class="post-metadata">

**Author:** ![smara](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smara](https://forums.unrealengine.com/u/smara)\
**Post date:** [July 31, 2016, 9:53am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/6 "2016-07-31T09:53:12Z")

</div>

I don’t really get your “sum up”-point.

How I understood it, OP wanted to create a UObject as a Subobject of an Actor. Furthermore he wanted to call a NetMulticast-Function from this **Subobject** (UObject, not Actor!).

The problem which is highlighted in this question is to actually **understand why _UObjects_ won’t allow RPCs.**

I think, you currently assume, that he tries to call a NetMulticast-Function from the client. And then you are right. This function would only get executed on the client.  
So first you(the client) would sent a _Server_ RPC to the server. And then the server sends a _NetMulticast_ to broadcast this info to all clients.

---

<div class="post-metadata">

**Author:** ![Anonymous\_dd56a58405288d59cf93311503aeeb3e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_dd56a58405288d59cf93311503aeeb3e](https://forums.unrealengine.com/u/Anonymous_dd56a58405288d59cf93311503aeeb3e)\
**Post date:** [October 13, 2016, 9:58am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/7 "2016-10-13T09:58:10Z")

</div>

if i call the rpc function of uobject in playercontroller in server , the uobject alse cant netmulitcast to other clients? why ?

---

<div class="post-metadata">

**Author:** ![smara](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smara](https://forums.unrealengine.com/u/smara)\
**Post date:** [October 13, 2016, 10:10am UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/8 "2016-10-13T10:10:07Z")

</div>

You would have to execute a NetMultiCast funtion which is _defined in an Actor or ActorComponent_. (e.g. your PlayerController from server)

This function would call the function of the UObject.

I guess you tried to tag the Function in your UObject as NetMultiCast and execute this function from your PlayerController. However it doesn’t really matter from where you try to call this function.

Point is, that the compiler tries to create an event from your ‘NetMultiCast’-tagged function. UObject alone is not able to create such an event without further help. Thus you have to create such RPC-Functions in classes like Actor, ActorComponent which can correctly transform your RPC-Functions into actual Events.

… or you have to figure out what you have to change at a UObject so that it can transform such a function to an event. I would be really interested in this.

---

<div class="post-metadata">

**Author:** ![Flakky](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flakky/32/918696_2.png) [@Flakky](https://forums.unrealengine.com/u/Flakky)\
**Post date:** [May 4, 2018, 12:30pm UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/9 "2018-05-04T12:30:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![uurkupeli](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@uurkupeli](https://forums.unrealengine.com/u/uurkupeli)\
**Post date:** [July 21, 2022, 3:49pm UTC](https://forums.unrealengine.com/t/rpc-doesnt-work-on-repicated-uobject/360736/10 "2022-07-21T15:49:57Z")

</div>

Thanks, this was immensely helpful.
