Project Settings Not Correct?

Five days I’ve been trying to make a simple connection between two players, to spawn them and let them walk around the map. Well, the connection and the spawning thing works, but something else fails:

Here’s what happens:

1 - Server starts - the server’s player can walk around and it works great
2 - client connects
3 - server loses control over his player and whatever he does, he can’t move it
4 - when client moves, he moves the server’s player too.

I tought it’s because of the player script, but it seems the problem is somewhere else (the project maybe). I opened M2H’s networking project and started the Authoritative server example and it worked great, then I decided to just copy the spawner and the player scripts from the tutorial into my project and scene and when I used them the same problem occured, that I had with my player.

Now, I wrote a topic for that before, but nobody managed to help me, so now I’ll make it more informative by supplying pictures and the spawner and player scripts. I tried to copy everything from M2H’s example to my project (the game objects’ components, their settings and everything) and still didn’t work.

So I have a spawner object, which looks like this:

And a player prefab with some children, that looks like this:

Run in Background is set from the project options.
I’m attatching the scripts below, please help me fix this problem, I can’t get this to work since wednesday :frowning:

436285–15169–$Player.js (5.6 KB)
436285–15170–$Spawner.js (650 Bytes)

Nobody? Seriously guys, I’m even willing to pay for help on this one.

Uh… I don’t have any experience with the network stuff, (I’ll get to it eventually) so I don’t know how much I can help.

I think your problem may be here in the spawn script

function OnServerInitialized(){
	Spawn(Network.player);
}

Network.player isn’t just an int, it’s a whole object, and your parsing it to an int later. I don’t think that is the correct way to do it, but I’m not sure at all since I’ve never messed with networks in unity. Sorry I can’t be of more help. I think that the new player is taking over the original players network id because of parsing it as an int. If it’s parsing both as the number 0, then the new person would get control, because the last option is for the group number. So, try just adding one to a global int in the spawn script that adds one every time someone joins. Example:

#pragma strict
#pragma implicit
#pragma downcast

var playerObject : GameObject;
private var playerTransform : GameObject; 
private var playerNumber = 0;

function OnServerInitialized(){
	Spawn(Network.player);
}

function OnPlayerConnected(connectedPlayer: NetworkPlayer) {
	Spawn(connectedPlayer);
}	

function Spawn(connectedPlayer : NetworkPlayer){
	playerNumber +=1;
	playerTransform = Network.Instantiate(playerObject, transform.position, transform.rotation, playerNumber);
	var playerNetworkView : NetworkView = playerTransform.networkView;
	playerNetworkView.RPC("PlayerSetup", RPCMode.AllBuffered, connectedPlayer,  playerNumber);
}

Try that and see if it works. (I’m practically guessing, but I’m sure you did that a bit before asking for help)

As far as the no one responding, not to many people use unity to make network games, so many of the people that may help with other things just don’t actually know how to help. I tend to pick things up quickly, and I have worked with network stuff in different languages, so I kind of understand what’s going on.

Hi! Thanks a lot for your respond (I’ve been trying to fix this for a week). I really wish I could say it worked, but I had no luck with it :frowning:
I didn’t think of declaring the player number variable before the whole thing, that makes sence, but the problem still occurs no idea why.

Well, I have a blury idea, but I’m not sure.

I got a question:

Wouldn’t this line here make all the clients’ player numbers one ? This script is ran on every machine and the variables don’t get seriallized, so for this thing wouldn’t I have to use an RPC ?

I think this thing now works like:

  • Server’s player connects, playerNumber = 0 +1 = 1
  • Server gets 1
  • Then client connects: on the server playerNumber = 1+1 = 2, but on the client’s machine: playerNumber = 0 + 1;

But that wouldn’t explain why it keeps behaving like that. In this case the client shouldn’t have any control over his player, but the same thing happens.

Oh, and last thing:

public var playerPrefab : Transform;
public var playerScripts : ArrayList = new ArrayList();

function OnServerInitialized(){
	//Spawn a player for the server itself
	Spawnplayer(Network.player);
}

function OnPlayerConnected(newPlayer: NetworkPlayer) {
	//A player connected to me(the server)!
	Spawnplayer(newPlayer);
}	

	
function Spawnplayer(newPlayer : NetworkPlayer){
	//Called on the server only
	
	var playerNumber : int = parseInt(newPlayer+"");
	//Instantiate a new object for this player, remember; the server is therefore the owner.
	var myNewTrans : Transform = Network.Instantiate(playerPrefab, transform.position, transform.rotation, playerNumber);
	
	//Get the networkview of this new transform
	var newObjectsNetworkview : NetworkView = myNewTrans.networkView;
	
	
	//Call an RPC on this new networkview, set the player who controls this player
	newObjectsNetworkview.RPC("SetPlayer", RPCMode.AllBuffered, newPlayer);//Set it on the owner
}

This the part of the spawning script of M2H’s networking tutorial that looks like mine spawn script. They are oretty identical and this script works in their project, but not in mine. I opened their project and couldn’t see any difference in the way things are set uo there…
This is just the hardest thing I’ve ever faced during my work with Unity.

I thought that not a lot of people understand networking, but I was hoping someone like you could see my thread.
And thank you for your answer once again, though it didn’t help fix the problem, it helped me exclude one more option :slight_smile:

Hey, sorry to bump this topic like that, but you know, I still can’t figure out what’s causing this to happen. If nobody knows, can someone at least suggest a place where I can speak with someone, that makes networking and knows eventually howo to fix this problem? I know about Unity Answers, but I don’t find it as a better place to ask.

Actually, am I calling this correctly?

networkView.RPC(“CalculateMove”, RPCMode.Server, virtualZ, virtualX, sprinting);

This is the function that sets the moving variables.