Announcement

Collapse
No announcement yet.

Replication & UObjects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Replication & UObjects

    Hello everyone!

    I am trying to understand UE4's replication system a bit better, by trying to implement it into a little system I made.

    Currently, I have a UMyAnimNotify Notify that when is generated, goes to a UWorldSingleton Object, and passes it a TArray<FMyStruct> of data.

    I want that Object to, eventually, be a server authoritative object that replicates data back to the clients. Basically, client presses a button, this generates Notify to be spawned, which in turn gives data to Object, which is processed, and sent back to all clients (when & if required).

    At the moment I want to pass this TArray<FMyStruct> of data through a function call which I wrote as:

    UFUNCTION(reliable, server, WithValidation)
    void Server_SendData(TArray<FMyStruct> const& ArrayOfData);

    with .cpp implementations that are just empty:

    /*START SERVER COMMUNICATION*/

    bool UMyAnimNotify::Server_SendData_Validate(TArray<FMyStruct> const& ArrayOfData)
    {
    return true;
    }

    void UMyAnimNotify::Server_SendData_Implementation(TArray<FMyStruct> const& ArrayOfData)
    {

    }

    /*END SERVER COMMUNICATION*/


    but when I do this I get a ton of errors, namely:


    [...].gen.cpp(26): error C2511: 'void UMyAnimNotify::Server_SendData(const TArray<FMyStruct,FDefaultAllocator> &) const': overloaded member function not found in 'UMyAnimNotify'
    [...].h(15): note: see declaration of 'UMyAnimNotify'
    [...].gen.cpp(29): error C2671: 'UMyAnimNotify::Server_SendData': static member functions do not have 'this' pointers
    [...].gen.cpp(29): error C2227: left of '->ProcessEvent' must point to class/struct/union/generic type
    [...].gen.cpp(29): error C2352: 'UObject::FindFunctionChecked': illegal call of non-static member function
    UObject/Object.h(875): note: see declaration of 'UObject::FindFunctionChecked'

    [...].cpp(178): error C2511: 'void UMyAnimNotify::Server_SendData_Implementation(const TArray<FMyStruct,FDefaultAllocator> &)': overloaded member function not found in 'UMyAnimNotify'
    [...].h(15): note: see declaration of 'UMyAnimNotify'


    Am I missing something here? The documentation doesn't seem to be all that well written, and is all over the place, which makes it real hard to know where to start. I hope I can get some advice on how to approach this!

    Thanks in advance for any and all help!

    #2
    UObjects by default don't run replication.
    You need a Actor/Component owned by a Connection to host the RPC.
    | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

    Comment


      #3
      All UObjects have to send RPC's via an Actors net connection, and the actor also has to be the "Outer" of the object or the data channel will crash - so you can't do this for Anim Notifies.

      The object calling the RPC must itself also be replicated. Usually this is done by overriding ReplicateSubObjects on the Actor itself. That being said, UObject replication can still be messy - especially when you take relevancy into consideration. Your best bet is to create a custom actor component which interfaces with the animation notifies, and send/receive data through that.

      Comment


        #4
        Thanks BrunoXavier and TheJamsh for your quick responses!

        So basically, since I currently have a UObject world singleton AND a UAnimNotify, my whole idea won't work, correct? Instead, I should change my UObject world singleton to be an AActor world singleton, and create a layer of indirection from the UAnimNotify such that instead of doing UAnimNotify->Singleton, it'd be UAnimNotify->Actor->GetMyComponent->Singleton

        Is that correct?

        Comment

        Working...
        X