How to replicate interaction?

I’ve been working on a multiplayer project for a while now with knowledge that I’ve just been getting from forums and tutorials, so I’m quite the novice.

I currently am using a method for this that I got from another user on here who has helped me a lot but I’m running into a problem with this where changes aren’t replicated to the client, and the client cant interact with the object.

This is the code for the interaction and the event that fires off in the object when interacted:

code inside the interactable object:

I cant get a video RN but basically what happens is the server player can interact with the interactable and change spotlight colour but the client literally does nothing when they interact with the object and they cant see the servers changes

try repnotify, it might suit your needs. here is quick example how to use it

You need to finish the tutorial. Part 2 goes into more detail and tweaks including the use of RepNotify.

Looking over both tutorials now and wanted to ask; does the code need to be set up any different? as I am using a listen client setup.

Main reason I ask is because the beginning of the tutorial says to make the interact only execute for clients and i assume that wouldn’t work for a listen server with a player acting as the server.

I’ve discovered that what’s happening is when the client player calls the RPC for the line trace the server trace is spawning from the hosting players (server) world location. still unsure of a fix though

Check the comments in vid 1 & 2. Listen server is covered in a few.

Looked through the comments and didn’t really find much of use, the main problem that I’ve now identified is that the world location for the camera will always default to the hosting player’s camera location when it is called through the server.

There is only one time where this doesn’t happen and that’s by removing the authority check for world location entirely and just using the camera component’s world location. Problem with this is that it doesn’t update for the client when crouched, so when the client crouches the trace stays at standing height, this makes no sense because the players camera location is moved down around 50 units when crouched.

New code:

Client problem:

On listen server the “Host” is also a client. The host will process input just as a normal client does. You have to consider this in your setup.

You can create a custom macro that works similar to Switch has Authority.


Your above code needs to use Camera Manager → Camera Location as well.

Server proxies do not update the Camera “Components” location. This is why when crouched the traces are coming from the default location.

Just for giggles here’s what the pre C++ translation BP looks like in a optimized setup.

  • Interfaces are used for all data requests and action/event calls.
  • Gameplay tags (C++ implementation) instead of actor tags.
  • Interaction type Handler Functions.

ok, I made a macro that checks the net role of the clients and now i get the world location by getting it from the player controller camera manager, new problem is that now it only uses the Client 0 (host)’s camera location no matter what client is interacting. I had this problem before and don’t know how to differentiate the two.

Show your code.

Also what pie mode are you testing in?

video of the code and the problem, server window is the left one, the trace always starts at the server player location when using the player controller setup, as for the pie mode im just using the new window one (if thats what you mean, if you mean a debug mode i’m not using one)

I’ll be in the office in roughly an hour… On mobile atm.

1 Like

There’s a few things funky in your setup.

First The Input logic flow does not need a switch check for host/client/authority. Only Clients or Host Client will process input.

Correct setup, regardless Listen or Dedicated.


Tweaking the Trace logic

First you absolutely need a clean reference to the controller for the given proxy executing the trace logic. I have no clue what your approach is to getting a controller reference, but it should not be Get Player Controller (index). Any node requiring a player index is for client-side only usage. They will always fail in a multiplayer game… Listen AND Dedicated.

You’re better off using Get Controller from the pawn class. This returns a generic Controller reference. From here you have 2 choices.

  1. Cast the return to Player Controller, then get Player Camera Manager → Get Camera Location

  1. [BETTER] Create an Interface for your controller and request the camera manager camera location data.


Finally the last sequence step…

Easiest approach is to swap the Switch has authority to a simple Is Server Branch check.

  • If you’re the server you’ll go right to interaction.
  • If you’re a client you’ll RPC the server to attempt interaction.

The alternative Macro/Function approach involves defining each proxy and using a switch.

Example…


As far as my previous question about PIE Mode…

2 Likes

This worked perfectly, didn’t realise that “Switch has authority” didn’t work in Listen server mode… but, now I know. Thanks so much!

Switch has authority does work on a listen server environment in general. Where and how it’s used is key. Understanding that it’s looking for network authority which is always the server… Dedicated, or listen host.

1 Like