x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

RPC doesn't work on repicated UObject

I've set up my UObject derived class properly (like recomended here). 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?

Product Version: UE 4.11
Tags:
more ▼

asked Jun 14 '16 at 11:56 AM in C++ Programming

avatar image

Sashka
93 15 23 24

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

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.

more ▼

answered Jun 24 '16 at 10:23 PM

avatar image

smara
67 6 9 15

avatar image Sashka Jul 08 '16 at 12:26 PM

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

avatar image smara Jul 10 '16 at 06:16 AM

Changed it.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered May 04 '18 at 12:30 PM

avatar image

AlFlakky
418 23 30 47

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

Reference: 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.

more ▼

answered Jul 29 '16 at 07:03 PM

avatar image

Sir Rogers
6 2 4 8

avatar image smara Jul 31 '16 at 09:53 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Oct 13 '16 at 09:58 AM

avatar image

少狼_
0 1 3 5

avatar image smara Oct 13 '16 at 10:10 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question