#Trying to set player roles using TargetRPC but they don't run on clients.

1 messages · Page 1 of 1 (latest)

ripe gate
#

I am making a hide and seek game, the server on game start sets the players roles in the game but nothing is running on clients.

If host is the seeker it works as intended but if the host isnt the seeker the nothing happens. The script is below:

Game Manager:

[Server]
public void SetSeeker()
{
int seekerIndex = Random.Range(0, gamePlayer.Count+1);

for (int i = 0; i < gamePlayer.Count; i++)
{
    if (i == seekerIndex)
    {
        gamePlayer[i].RPCSetSeeker();
    }
    else
    {
        gamePlayer[i].RPCSetHider();
    }
}

}

Player Object:

[TargetRpc]
public void RPCSetSeeker()
{
isSeeker = true;
}
[TargetRpc]
public void RPCSetHider()
{
isSeeker=false;
}

brazen frost
#

Anything in console, on both server and connected client whilst you run the code? (check yellow warnings too)

#

add some prints of debug logs in the functions

ripe gate
#

So the SetSeeker is in the network manager, it cycles through each player in game players which is a List of all connected clients and for each grabs the RPCSetSeeker for each game player which is on each object. There is nothing in console

brazen frost
#

🤔

ripe gate
#

By my calculations It should work but doesnt haha

brazen frost
#

I guess add checks into each section, make sure everything is behaving as expected.

#
for (int i = 0; i < gamePlayer.Count; i++)
    {
print("test 1: " + gamePlayer.Count);
...
 if (i == seekerIndex)
        {
print("test 2 ");
#
public void RPCSetSeeker()
{
print("RPCSetSeeker");
#

etc

ripe gate
#

Ok, I have set a debug. The target RPCS are running but only for the host

#

I set the spawns based on their role and only the host is also being moved. It isnt doing it for each player

trail bane
ripe gate
#

Set seeker is running on awake when the scene changes to the game scene. Each player has an object controller with the isSeeker variable.

[SyncVar] public int connectionID;
[SyncVar] public int playerID;
[SyncVar] public ulong playerSteamID;
[SyncVar(hook =nameof(PlayerNameUpdate))] public string playerName;

[SyncVar] public bool isSeeker;

#

I dont set in onserverstart because I want the game to be a party game so when the round has ended I need set seeker to be set again so the same person isnt seeker each time

trail bane
#

"[SyncVar] public bool isSeeker;

Why would you be calling TargetRpc to set that? It's a SyncVar!

ripe gate
#

Does it need to be a syncvar or is there another way to set>

#

Is syncvar just not to make the variable show the same thing for all clients?

#

Ok this is working. Thanks for the help! everyone is set as their role...

New issue, I want to move each player after a time to their spawn point to not start together. I would appreciate if pointed in the right direction

https://pastie.io/vqkytq.cs

trail bane
ripe gate
#

Updated

trail bane
ripe gate
#

I have tried using the network start position and it hasnt worked. They still spawn at 0,0,0

trail bane
#

We use them in many examples...they work fine unless you did something weird

ripe gate
#

Nothing weird, i added to an empty and it doesnt work.

trail bane
#

well duh - you override OnServerAddPlayer. You can set those values in OnStartServer of PlayerObjectController

#

Look at what the base OnServerAddPlayer does, calling GetStartPosition

trail bane
ripe gate
#

Forgive me for asking basic questions, this whole networking thing is new to me. When changing scene, to have the seeker spawn in a different place to hiders using network start position. What steps should be taken to make this work?

#

Ok not to worry, in the documentation I can see for myself

#

Thanks for the help

trail bane
ripe gate
#

Ok and if I wanted seeker to spawn at a specific spawn point, each spawn point Is in a list so can get the spawn points from NetworkManager.startPositions

trail bane
ripe gate
#

right so for hiders just use network start position but seeker I would need to manually set its position like how I was before?

trail bane
ripe gate
#

Right, Server Add Player runs even when changing scenes?

trail bane
ripe gate
#

Right! I has players aas DDOL but this makes life easier haha.

trail bane
#

I'm saying DON'T do that

ripe gate
#

Yeah im realising now thats a mistake

trail bane
#

let them be destroyed by the scene change and Mirror will call OnServerAddPlayer again after they change for each one