Announcement

Collapse
No announcement yet.

Smooth Sync: Sync your Transforms Smoothly across the network

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

  • replied
    Vaei
    Sorry, I'm new to Unreal so the terminology is a little different. When I said the server owns the object I meant it is owned by the Actor that is controlled by the person who is running the server on their computer. Thanks for the definition tips.

    I believe your replication problem is because your object is set up incorrectly. Even Unreal's replication doesn't work with your set up. I think it's because you are trying to replicate something else's position and not the cube's. Drag the cube into the level first and then put a blueprint on that and it will replicate the cube's movement. Check out this post with relevant Unreal Stack Overflow explanation and a screenshot.

    I do not understand how you can call RPCs from objects you don't own anyway. I don't think anyone can just call an RPC on any object that they want without ownership.

    Client RPCs: "If the RPC is being called from client to be executed on the server, the client must own the Actor that the RPC is being called on."
    And MultiCastRPCs: "If they are called from clients, they will only execute locally, and will not execute on the server."

    Typically I would think you would send over an RPC to the server which would then send an RPC to PlayerControllerB (the owner in your scenario).

    It will take some time to process and research a bit more about your second post so I'll reply to that later. Thanks for the tips!
    Last edited by fuestrine; 08-03-2018, 06:51 PM.

    Leave a comment:


  • replied
    Looking through your source now.

    First, please stop using GetPlayerController 0, you'll see it in tutorials a lot and should rarely actually be used and many tutorials are made by people who hacked a solution and thought to share it, not experienced devs. Rule of thumb - if you can't get a reference properly, you're doing something wrong. It returns the first local player controller and that is rarely what you actually want - especially on the server.

    In your case, you don't really need to find a better way to get the player controller because this plugin wont work with an owner for reasons already mentioned.

    This piece of code here is nasty:

    Code:
        // TODO: Is Unreal really going to make me send my own information back out to myself?
        // look up a better way.
        // If I own the object, don't sync it.
        if (realObjectToSync->GetOwner() == UGameplayStatics::GetPlayerController(GetWorld(), 0))
        {
            return;
        }
    If the owner is a player controller, you can just check if it's a local player controller, or even GetOwner()->GetNetConnection() != nullptr which pretty much works because of the entire problem you're facing - no one else can call RPCs on it.

    For this plugin to work, clients must not send their data. You really should simply be replicating the information and not multicasting it, it's a waste of bandwidth. Replication is much more efficient.

    It seems common to just have the server control the position in Unreal when there is no owner though so I might implement it in the next update.
    That should do it
    Last edited by Vaei; 08-03-2018, 06:27 PM.

    Leave a comment:


  • replied
    The most important thing here is that servers do not own objects. Servers have authority over objects. Actors own objects. If you set PlayerControllerB to the owner, then PlayerControllerB owns that object - not the server, and PlayerControllerA and PlayerControllerC can not call RPCs and can not send the information that would otherwise be required to sync.

    As such, if it wont work without ownership, then it's a little pointless.

    Maybe it's a bug in the current version but it actually doesn't sync at all, regardless. I made a new blueprint, added a cube, set the cube to simulate physics, set the blueprint to 'Replicates'. Just doesn't do it.

    Look at this video - the character is being corrected when hitting the box on either the client or server, because it's not synced.

    https://streamable.com/v39ye

    Leave a comment:


  • replied
    Vaei
    If there is 3 players, and the server sets a player as the owner, that owner replicates to all players and that player now owns the ball. That player can call RPCs. The rest can't. That's useless because they all need to sync it.
    The rest don't need to call an RPC. The owner needs to send an RPC of the transform to the server (possible because of ownership). The server then needs to send out the position to all clients (possible because it's the server). I recognize that the server is then sending back to the owner though.

    doesn't get called as something becomes relevant like replication does.
    Unreliable RPCs take NetCullDistanceSquared into account. If you mean something else for relevancy, let me know and I can test anything you might be questioning.

    it needs to be purely replication based
    Can you have the client change variables and have it replicate out to the server and all other clients? I thought it was purely server controlled.

    Also.. stuff lying around in the world, where you'd likely actually use this, isn't owned. That's the point.
    That's why I have a "SetOwnerToServer" variable, so the user doesn't need to do anything extra for that. I do understand that multi-cast can send from server to clients regardless of ownership though. I'll think about automatically making the server control the position, but I liked the explicit nature of having to set up server ownership so that the user knows exactly who is controlling the position. It seems common to just have the server control the position in Unreal when there is no owner though so I might implement it in the next update.

    Let me know if I misunderstood anything or if you have more questions. Cheers.
    Last edited by fuestrine; 08-03-2018, 01:42 PM.

    Leave a comment:


  • replied
    Something isn't adding up.

    Lets say there is a ball that players can walk into and it gets kicked around. This ball needs an owner for RPCs.

    If there is 3 players, and the server sets a player as the owner, that owner replicates to all players and that player now owns the ball. That player can call RPCs. The rest can't. That's useless because they all need to sync it.

    You can't use RPCs for a system like this, it needs to be purely replication based. Even if you can multicast, you shouldn't, it's more bandwidth intensive and doesn't get called as something becomes relevant like replication does.

    Also.. stuff lying around in the world, where you'd likely actually use this, isn't owned. That's the point.
    Last edited by Vaei; 08-03-2018, 09:10 AM.

    Leave a comment:


  • replied
    iCode
    Good idea. I was starting small so as to have fewer chances at issues. I'll put out some versions that aren't 4.19 in the next few days, including 4.20.

    I'll message you when 4.20 is up on the store.
    Last edited by fuestrine; 07-26-2018, 11:02 AM.

    Leave a comment:


  • replied
    Are you going to support 4.20?

    Leave a comment:


  • replied
    Originally posted by fuestrine View Post
    I just tested NetCullDistanceSquared and it does not receive messages if they are passed the limit when using unrealiable RPCs.
    Thank you for sharing that.
    It is something I did not know and will hopefully come in handy for others

    Leave a comment:


  • replied
    Kris
    Ah, I see. I'm still conflicted on if I want to sync to server automatically when there is no owner but I'll definitely look into it.

    I just tested NetCullDistanceSquared and it does not receive messages if they are passed the limit when using unrealiable RPCs.
    Last edited by fuestrine; 07-25-2018, 01:36 PM.

    Leave a comment:


  • replied
    fuestrine Oops, yeah mean "No" as in "No you don't need an owner" in response to "Are you saying that setting owner to server is basically redundant since I can just use multi-cast to send from server regardless?".

    Sorry about the confusion.

    > "I'm pretty sure unreliable RPCs use NetCullDistanceSquared so I don't think passing information through another system will do anything different for that."

    It was my understanding that it simply meant it may/may not make it to the client.
    See Reliable vs Unreliable Function Call Replication.

    Leave a comment:


  • replied
    Kris
    What are you saying no to? I still need ownership to send from clients to server as far as I understand.

    I do understand that multi-cast can send from server to clients regardless of ownership though. I'll think about automatically making the server act as the owner and control the position, but I liked the explicit nature of having to set up server ownership so that the user knows exactly who is controlling the position. It seems common to just have the server act as the owner in Unreal though so I'll probably implement it in the next update. Thanks for the tip.

    I'm pretty sure unreliable RPCs use NetCullDistanceSquared so I don't think passing information through another system will do anything different for that.

    Leave a comment:


  • replied
    fuestrine No, you don't need an owner for a multi-cast to all clients.
    That said, it will go to *all clients*, regardless of relevancy.
    I'm not sure if that was intended or not.
    Was going to pass the information via the regular replication system instead.
    That way the game is not sending updates to players that can't possibly see the actor/component being updated.

    Leave a comment:


  • replied
    Kris
    I'm no expert in Unreal so let me know if I'm confusing anything.

    Are you saying that setting owner to server is basically redundant since I can just use multi-cast to send from server regardless?

    If you mean the entire project doesn't need to set an owner, I'm very confused because I thought you needed to have the client as an owner to be able to send RPCs from the client to the server.

    Leave a comment:


  • replied
    Been looking thought the code a bit and that had me confused - I'm not sure what you intended when you set that.
    The only time you'd need to set the owner to a player controller, player state or similar is when you would need to replicate information directly from client to server/server to client.
    From the look of it, there is a multi-cast involved at the moment, which doesn't need an owner.
    Yeah... so, bit confused :P

    Leave a comment:


  • replied
    GrumpyNZ
    I'm not entirely sure what you are asking but you'll probably want to uncheck the Set Owner To Server checkbox if you are trying to set owner as not server.

    I'm not sure what the best way to set up ownership is for your situation but you'll have to set up ownership in order to sync your Actors.

    I use
    Code:
    if (setOwnerToServer && realObjectToSync->GetWorld()->IsServer())
        {
            realObjectToSync->SetOwner(UGameplayStatics::GetPlayerController(GetWorld(), 0));
        }
    to set up ownership on the server.

    You can increase the number to get other player controllers if they are connected. Only the server knows every client's player controller. I'm not sure about using player states instead.

    Forums are good for me.

    Let me know if I misunderstood what you were asking or if you have more questions.
    Last edited by fuestrine; 07-24-2018, 11:59 PM.

    Leave a comment:

Working...
X