Announcement

Collapse
No announcement yet.

Basic Replication, Setting an owner to server?

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

    Basic Replication, Setting an owner to server?

    Ive just started to dice into replication and I cannot for the life of me figure out this small little part. What i do in my code:
    -Player pushed button, to call function "Cast Interaction Ray" in which the function is located in an Interaction Actor Component.
    Click image for larger version

Name:	playerCharacter.PNG
Views:	230
Size:	61.6 KB
ID:	1554666
    -From here we check if we hit something, and if this hit implements the "interaction interface"
    -If it does implement the interface, then it's "Interact" event/function in the actor
    -From here we determine what to do, in this case, we attempt to ad it to our inventory, then destroy it
    Click image for larger version

Name:	Interactable.PNG
Views:	276
Size:	167.0 KB
ID:	1554665
    And that's where it breaks down client side.

    Now from what I've gathered, to call a RPC from some random object in the world, it needs to have an owner. To quickly attempt to get around this, right before I call the Event on the server i set the owner just to whoever is interacting with the object(im sure this is all bad/incorrect to do but just temporary to see if anything would change.)
    Doing this allows me to call the event, and it does run. But even then in my code, its supposed to destroy the object which is doesnt do. Is it possible to just set the owner to the server? I'm curious what the CORRECT way to do this is! Or a decent tutorial because I cant seem to find anything with this scenario.

    Any info helps!
    Attached Files

    #2
    Setting a server as Owner is redundant since the purpose of Ownership is to allow Clients to send RunOnServer Remote Procedure Calls (RPC's) to the Server or the Server to send RunOnOwner RPC's to the owning Client if any.

    A Server can always replicate variables or do Multicast Events on Actors that are set to Replicate while it is relevant to the specific Client.

    Note that when you change Ownership (Set Owner) it has to be done by the Server. Client's can't change Ownership by themselves.
    Also note that the Server has to Spawn actors that are replicated for the replication to work. If a client spawns a replicated actor it will work as a non-replicated actor.

    Like with Spawn you should only Destroy Actors from the server and it will clean up the Actors on the clients.
    Last edited by GarnerP57; 11-22-2018, 03:26 PM.

    Comment


      #3
      Originally posted by GarnerP57 View Post
      Also note that the Server has to Spawn actors that are replicated for the replication to work. If a client spawns a replicated actor it will work as a non-replicated actor.

      Like with Spawn you should only Destroy Actors from the server and it will clean up the Actors on the clients.
      Thanks for the help!

      Still having issues though
      So how can i tell the Server, from the Client, to destroy the actor? Currently my event(ServerRunInteract) is set to Multicast. All the code is ran correctly, but it will not destroy the actor on Client or Server(if player is a client)

      This BP is from an actor that is placed in the world..


      EDIT: is it having to do with my Interface thats causing an issue?

      EDIT 2: OKAY i got it working. the issue was my player was calling a function in the "Interaction" actor component which was calling the interface function.
      What i did to fix it was intstead of directly calling the interface function, i call a custom event on the server, which then calls the interface function.

      Only issue i have not is objects that are placed via level blueprint are only being destroyed for the user that interacts with it, but objects placed manually work fine
      Click image for larger version  Name:	Interactable.PNG Views:	1 Size:	148.0 KB ID:	1554910
      Last edited by zachgibson22; 11-22-2018, 05:17 PM.

      Comment

      Working...
      X