0
\$\begingroup\$

I am making a multiplayer RTS but I have a problem controlling spawned units (let's call them Vessels), specifically moving them around with AI MoveTo bp.

Vessels can be created by both Clients and Server and are visible for everyone but neither clients nor Server can move Spanwed Vessels.

Only Vessels placed on the map beforehand can be moved and ONLY by the Server.

Also, the server sees all Client CameraPawn movements and clients see Server CameraPawn movements BUT clients don't see each other's CameraPawn Movements (if this is related somehow...)

  1. How can I control a pawn in multiplayer from all clients for starters?
  2. How can I limit control to a specific controller?
  3. Why "preplaced" Vessels work(move) for Server only?
\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

I finally solved my problem and I guess I misunderstood some things. It appears that the server must do everything, regardless of whether the code appears to be executed on clients or not...

I ended up passing the location and pawn I wanted to move to a function that executed on the Server and there I ran the entire code.

Simply put, I just could not see it :)

@Stephen Thanks for the reply :D

\$\endgroup\$
2
  • \$\begingroup\$ Glad you sorted it in the end. And yes, the Unreal model is that the client tells the server what it wants to do, the server checks if the client can then does or does not it happen accordingly on all client models. Get used to using HasAuthority() a lot. :o) \$\endgroup\$
    – Stephen
    Commented Sep 11, 2020 at 12:12
  • 1
    \$\begingroup\$ If this is the way to solve the issue you had, you should consider marking it as the accepted answer :) \$\endgroup\$
    – Vaillancourt
    Commented Feb 11, 2021 at 14:52
0
\$\begingroup\$

If your spawned vessels aren't moving but those placed previously are then it's likely one of two things is happening.

Either the BP is set to Auto AI possess placed in level only and not spawned or placed in world: Spawn Or Placed In World AI Possess Example

The other option would be that you haven't correctly assigned the AI Controller when spawning. The easiest way to check this would be that after the spawn actor from class call, get the AI Controller and print it out. If it's not the controller you were expecting then it's not assigning correctly.

To limit control to a specific controller, you'll need to create a new variable which you'll need to make public and Expose on Spawn. This will put a new pin on your Spawn Actor class you can plug into for a unique reference to whichever controller spawned the vessel and can be checked against when attempting to select / move the vessel.

\$\endgroup\$
2
  • \$\begingroup\$ I did what you suggested and now the units move but only the server can move them or actually do anything at all such as destroy them. I use NetMode -> Play as client and only the server and functions with Replicates -> Run On Server do anything at all. Clients can initiate Funcs for the server to run but can't interact with the objects in any way example: select an object and tell the server to move or destroy it (destroy actor)... Any insight on this? (For the life of me i am on this from 8th of Sept and found no solution whatsoever :((( ) \$\endgroup\$
    – SomeDude
    Commented Sep 10, 2020 at 21:26
  • \$\begingroup\$ TL;DR Clients can't interact with Spawned units no matter where i execute the interaction (Run on server, Multicast or Otherwise) \$\endgroup\$
    – SomeDude
    Commented Sep 10, 2020 at 21:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .