Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joeconstable97 · Aug 04, 2013 at 05:48 PM · instantiatenetworkviewidowner

Network Instantiate with wrong owner.

Hey everyone, I recently came across a problem in my multiplayer game. It all works when there two players (server and client), then the third player joins and everything works, until it gets to the buffered network instantiate. The problem is that the both players that were all ready in get instantiated for the new player, but both are owned by the server (the networkview.owner is the server). Script:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using CorruptedSmileStudio.MessageBox;
 
 
 public class MultiplayerManager : MonoBehaviour
 {
     public static MultiplayerManager instance;
     public string PlayerName;
     public string MatchName = "";
     private int MaxUsers = 32;
     private string MatchPassword = "";
     public int altprefix;
     public bool MatchStarted = false;
     public bool MatchedLoaded = false;
     public bool ShowStuff = false;
     //public bool IsInServer = false;
     public string CurrentType;
     public float Tod;
     private float NameOffsetY = -180;
     public LevelManager SceneManager;
     public Texture2D SpotTexture;
     //public bool FirstSpawn = false;
     
     public List<MpPlayer> PlayerList = new List<MpPlayer>();
     public List<RoomSettings> RoomSettings = new List<RoomSettings>();
     
     public RoomSettings Settings = null;
     
     public MpPlayer MyPlayer;
     public GameObject[] SpawnPoints;
     
     public GameObject PlayerManagerPrefab;
     public bool ChoosenTeam = false;
     public Texture2D PauseMenu;
     public GameObject[] SpawnPointsGood;
     public GameObject[] SpawnPointsBad;
     public bool ChoseDeploy = false;
     //public string GameMode;
     public bool Finished;
     public string Won;
     public Texture2D Grading;
     public GUISkin Skin;
     public int Tickets;
     public float Version;
     public Shader MinimapShader;
 
 
             
     void Start(){
         //Application.targetFrameRate = 60;
         MessageBox.RemoveFirst();
         networkView.group = 1;
         instance = this;
         PlayerName = PlayerPrefs.GetString("PlayerName");
         Settings = RoomSettings[0];
         DontDestroyOnLoad(gameObject);
         if(MatchedLoaded)
             MatchedLoaded = false;
         //MasterServer.ipAddress = "127.0.0.1";
         //MasterServer.port = 23466;
        // Network.natFacilitatorIP = "127.0.0.1";
         
         
         //Screen.lockCursor = false;
     }
     
     void Update(){
         //Color3Grading Col3 = 
 
         /*if (M2HPatcher_Runtime.HasLoadedVersion())
         {
             if (M2HPatcher_Runtime.NeedUpdate())
             {
                 //We need to update
                 if (GUILayout.Button("Update me!"))
                 {
 
                     M2HPatcher_Runtime.QuitAndStartPatcher();
                 }
             }
 
         }
          */
         //if (Input.GetKeyDown(KeyCode.P))
         //{
          //   Time.timeScale = 0;
         //}
 
         if (MatchStarted)
         {
             if (GameModeManager.Inst != null)
             {
                 if (GameModeManager.Inst.Score1 == Tickets)
                 {
                     EndGame("Sas");
                 }
 
                 if (GameModeManager.Inst.Score2 == Tickets)
                 {
                     EndGame("Mqr");
                 }
             }
         }
         
         
         if(Input.GetKeyDown(KeyCode.Escape)&& MatchedLoaded)
             ShowStuff = !ShowStuff;
     }
 
     [RPC]
     public void ResetEndGame()
     {
         
         
         SceneManager.EndCamera.SetActive(false);
         Finished = false;
         Won = "";
         ChoosenTeam = false;
         MyPlayer.Team = "";
     }
 
     public void EndGame(string whowon)
     {
         Won = whowon;
         Finished = true;
         SceneManager.EndCamera.SetActive(true);
         if(MyPlayer.PlayerIsAlive)
             MyPlayer.Manager.HandleBulletDamage(MyPlayer.PlayerHealth, true, MyPlayer.Manager.LastShootBy.PlayerNetwork, MyPlayer.Manager.LastShooterGun);
     }
     
     public void StartServer(string Name, string Password, int MaxPlayers,int Port){
         MatchName = Name;
         MatchPassword = Password;
         MaxUsers = MaxPlayers;
         Network.InitializeSecurity();
         Network.InitializeServer(MaxPlayers, 2550, true);
        
         MasterServer.RegisterHost("FrontLinesBonFireTz" + Version,MatchName,"In Lobby");
         
     }
     
     void OnServerInitialized(){
         ServerPlayerJoinRequest(PlayerName,Network.player,RankManager.Ins.CurLevel);
         //ClientAddPlayerToList(PlayerName, Network.player, RankManager.Ins.CurLevel);
     }
     
     void OnConnectedToServer(){
         networkView.RPC("ServerPlayerJoinRequest",RPCMode.Server,PlayerName,Network.player,RankManager.Ins.CurLevel);
         //StopCoroutine("ConnectBox");
     }
     
     void OnPlayerConnected(NetworkPlayer player) {
      //   if (Network.isServer)
       //  {
             foreach (MpPlayer pl in PlayerList)
             {
                 networkView.RPC("ClientAddPlayerToList", player, pl.PlayerName, pl.PlayerNetwork, pl.Level);
                 Debug.Log("Sent info on " + pl.PlayerName + " with the level of " + pl.Level + " and network id of " + pl.PlayerNetwork);
                 //    if(pl.PlayerIsAlive)
                 //    pl.PlayerManager.networkView.RPC("Client_ImAlive",player);
             }
 
             if (GameModeManager.Inst != null)
                 networkView.RPC("Client_GetMatchSettings", player, Settings.MapName, CurrentType, "", MatchStarted, Tod, Tickets, GameModeManager.Inst.Score1, GameModeManager.Inst.Score2);
             else
                 networkView.RPC("Client_GetMatchSettings", player, Settings.MapName, CurrentType, "", MatchStarted, Tod, Tickets, 0, 0);
      //   }
         //networkView.RPC("Client_GetTime", player, Time);
                 
            
         
         //if(MyPlayer.PlayerIsAlive)
             //MyPlayer.PlayerManager.networkView.RPC("Client_ImAlive",player);
     }
     
     void OnPlayerDisconnected(NetworkPlayer id){
         networkView.RPC("RemovePlayerToList",RPCMode.All,id);
         Network.RemoveRPCs(id);
     }
     
     void OnDisconnectedFromServer(NetworkDisconnection info) {
         foreach(MpPlayer mp in PlayerList)
         {
             Destroy(mp.Manager.gameObject);    
         }
         PlayerList.Clear();    
         //IsInServer = false;
         //Chat.SP.Messages.Clear();
         KillFeed.SP.Messages.Clear();
         Destroy(gameObject);
         Application.LoadLevel(1);
         if(info == NetworkDisconnection.LostConnection)      
             MessageBox.Show(null, "You have lost connection to the host.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
     
     [RPC]
     void ServerPlayerJoinRequest(string nam, NetworkPlayer id, int Level)
     {
         networkView.RPC("ClientAddPlayerToList", RPCMode.All, nam, id, Level);
     }
 
     void OnNetworkInstantiate(NetworkMessageInfo info)
     {
         Debug.Log("Made player object for " + info.sender);
     }
     
     [RPC]
     void ClientAddPlayerToList(string namee, NetworkPlayer id,int Level){
         
     //    IsInServer = true;
         Debug.Log("Adding "+namee + " with network id of " + id + " to the player list");
         MpPlayer tempPlayer = new MpPlayer();
 
         tempPlayer.PlayerName = namee;
         tempPlayer.PlayerNetwork = id;
         Debug.Log("Just created player with ID: " + id);
         tempPlayer.Level = Level;
         
         PlayerList.Add(tempPlayer);
         if (Network.player == id)
         {
             MyPlayer = tempPlayer;
 
            GameObject Player = Network.Instantiate(PlayerManagerPrefab, Vector3.zero, Quaternion.identity, 5) as GameObject;
            //Player.networkView.viewID = Network.AllocateViewID();
            Debug.Log("Made player object for " + namee);
             //Player.GetComponent<PlayerManager>().thisPlayer = MyPlayer;
             //Player.GetComponent<PlayerManager>().thisPlayer = MyPlayer;
             //MyPlayer.Team = Random.Range(0,2);
             
             
             
             //MyPlayer.NameMesh = MyPlayer.PlayerManager.OutSideView.transform.FindChild("NameText").GetComponent<TextMesh>();
             //MyPlayer.NameMesh = MyPlayer.PlayerManager.NameMesh;
             //MyPlayer.NameMesh.text = MyPlayer.PlayerName;
         }
         //if(MatchStarted)
         //    GetMPPlayer(View).PlayerManager.networkView.RPC("Client_LoadMap",GetMPPlayer(View).PlayerNetwork);
         
         //GameObject Tag = Instantiate(NameTagObject,Vector3.zero,Quaternion.identity) as GameObject;
         //Tag.GetComponent<ObjectLabel>().TargetPlayer = GetMPPlayer(View);
         //Tag.GetComponent<GUIText>().text = GetMPPlayer(View).PlayerName;
         //Tag.GetComponent<ObjectLabel>().target = GetMPPlayer(View).
         //Tag.GetComponent<ObjectLabel>().cameraToUse = MyPlayer.PlayerManager.Controller.CamHolder.camera;
         
         //DontDestroyOnLoad(Tag);
     }
     
     [RPC]
     void RemovePlayerToList(NetworkPlayer View){
         //IsInServer = false;
         MpPlayer temp = new MpPlayer();
         foreach(MpPlayer pl in PlayerList){
             if(pl.PlayerNetwork == View){
                 temp = pl;    
             }
                 
         }
         if(temp != null){
             PlayerList.Remove(temp);
             Network.Destroy(temp.Manager.gameObject);
             chat_manager.inst.networkView.RPC("GetMessage", RPCMode.All, Network.player, temp.PlayerName + " has left");
         }
             
     }
     
     [RPC]
     void Client_GetMatchSettings(string map, string mode,string others,bool started,float toime, int ticks,int Points1,int Points2){
         Settings = GetMap(map);
         MatchStarted = started;
         CurrentType = mode;
         Tod = toime;
         Tickets = ticks;
         if (GameModeManager.Inst != null)
         {
             
             if (MultiplayerManager.instance.CurrentType == "Team Deathmatch")
             {
                 GameModeManager.Inst.TeamDM.Team1Score = Points1;
                 GameModeManager.Inst.TeamDM.Team2Score = Points2; 
             }
             else if (MultiplayerManager.instance.CurrentType == "Control Points")
             {
                 GameModeManager.Inst.ControlPoints.SasPoints = Points1;
                 GameModeManager.Inst.ControlPoints.MqrPoints = Points2; 
             }
             else
             {
                // GameModeManager.Inst.Planter. = 0;
                 GameModeManager.Inst.Planter.Team2Score = Points2; 
             }
         }
         if(started)
             Client_LoadMap(map,altprefix + 1);
     }
 
     
 
     [RPC]
     public void UpdateRank(string Playername, int Rank)
     {
         GetMPPlayer(Playername).Level = Rank;
     }
     
     
     public RoomSettings GetMap(string name){
         RoomSettings get = null;
         
         foreach(RoomSettings rs in RoomSettings){
             if(rs.MapName == name || rs.MapLoadName == name){
                 get = rs;
                 break;
             }
         }
         
         return get;
     }
     
     [RPC]
     public void Client_LoadMap(string map, int prefix){
         altprefix = prefix;
         MultiplayerManager.instance.MatchStarted = true;
         Network.SetSendingEnabled(0, false);
         Network.isMessageQueueRunning = false;
        // Network.RemoveRPCs(networkView.owner);
        // Network.RemoveRPCsInGroup(69);
       //  Network.SetSendingEnabled(0, false);
     //    Network.isMessageQueueRunning = false;
         //networkView.viewID = Network.AllocateViewID();
         Network.SetLevelPrefix(prefix);
         Application.LoadLevel(map);
         Network.isMessageQueueRunning = true;
         // Now the level has been loaded and we can start sending out data to clients
         Network.SetSendingEnabled(0, true);
      //   Network.isMessageQueueRunning = true;
     //    Network.SetSendingEnabled(0, true);
         
         
         
         //MatchedLoaded = true;
         
        foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);   
         
     }
 
     void OnFailedToConnect(NetworkConnectionError error)
     {
         MessageBox.Remove("Connecting, Please wait...");
         MessageBox.Show(null, "Error Connecting to server: " + error.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.None);
     }
     
     void OnGUI(){
         if(!MyPlayer.PlayerIsAlive && MatchedLoaded && ChoosenTeam)
             SpawnMenu();
         /*if(MatchedLoaded){
             if (Network.isServer)
                 GUI.Label(new Rect(0, 0, 128, 32), "You are the Host");
             GUI.Label(new Rect(0, 33, 128, 32), "Ping: " + Network.GetAveragePing(Network.player).ToString() + "MS");
         }
          */
         
         if (Network.peerType == NetworkPeerType.Connecting) {
             GUI.Box(new Rect((Screen.width / 2) - 128, (Screen.height / 2) - 64, 256, 128), "Connecting...");
         }
 
             
         if(ShowStuff){
             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), PauseMenu);
             GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
             if(MyPlayer.PlayerIsAlive){
                 if (GUILayout.Button("Suicide", GUILayout.Width(Screen.width / 3.57f), GUILayout.Height(32)))
                 {
                     MyPlayer.Manager.HandleBulletDamage(MyPlayer.PlayerHealth, true, MyPlayer.Manager.LastShootBy.PlayerNetwork, MyPlayer.Manager.LastShooterGun);
                    // Time.timeScale = 0;
                    
                     ShowStuff = false;
                     //MyPlayer.PlayerManager.LastShooterGun = "Suicide";
                     //MyPlayer.PlayerManager.LastShooterName = MyPlayer.PlayerName;
                     //KillFeed.SP.SendKillMessageToPeeps(RPCMode.All,MyPlayer.PlayerName,"","Suicide");
                 }
             }
             if(MatchedLoaded){
                 //Screen.lockCursor = false;    
                 if (GUILayout.Button("Disconnect", GUILayout.Width(Screen.width / 3.57f), GUILayout.Height(32)))
                 {
                     
                     MatchedLoaded = false;    
                     Network.Disconnect();
                     Destroy(MyPlayer.Manager.gameObject);
                     Application.LoadLevel(1);
                     
                     Destroy(gameObject);
                 
                 }
                 
             }
             GUILayout.EndArea();
         }
         
         if(MatchedLoaded && !ChoosenTeam){
             GUILayout.BeginArea(new Rect((Screen.width/2) - 128,(Screen.height/2) - 64,256,128),"Choose a team","box");    
             GUILayout.Space(32);    
                 foreach(Team str in Settings.Teams){
                     if(GUILayout.Button(str.Name)){
                         ChoosenTeam = true;    
                         MyPlayer.Team = str.Name;
                         if (str.Name == "Sas" && GameModeManager.Inst.Alim != null)
                         {
                             GameModeManager.Inst.Alim.SasPlayerLives.Add(new Lives(MyPlayer));
                         }
                         else
                         {
                             GameModeManager.Inst.Alim.MqrPlayerLives.Add(new Lives(MyPlayer));
                         }
                         ChoosenTeam = true;    
                         networkView.RPC("Client_SetTeam",RPCMode.Others,str.Name,MyPlayer.PlayerName);
                         ChoosenTeam = true;    
                     }
                 }
     
             GUILayout.EndArea();
         }
 
         if(MatchedLoaded == true && MyPlayer.Team != ""){    
             foreach (MpPlayer mp in PlayerList)
             {
                 if (mp != MyPlayer)
                 {
                     if (mp.Team == MyPlayer.Team && mp.PlayerIsAlive)
                     {
                         if (mp.Manager != null)
                         {
                             //// foreach( Collider c in mp.PlayerManager.OutSideView.GetComponent<ThirdPersonColliderHolder>().Colliders)
                             /// {
                             //      c.enabled = false;
                             //  }
                             GUI.color = Color.green;
                             //Vector2 pos = Manager.MainCamera.WorldToScreenPoint(Veh.position);
                             Vector3 pos = Camera.main.WorldToScreenPoint(mp.Manager.HudRef.position);
 
                             Vector3 pos1 = mp.Manager.HudRef.position - Camera.main.transform.position;
                             //Vector2 offs = new Vector2(0, NameOffsetY);
                             if (Vector3.Dot(Camera.main.transform.forward, pos1) > 0)
                             {
                                 GUI.Label(new Rect(pos.x, (Screen.height - pos.y) - pos.z / Camera.main.fieldOfView, 155, 155), mp.PlayerName);
                             }
                             GUI.color = Color.white;
 
                         }
                     }
                 }
             }
         }
 
         if (Finished)
         {
            // GUILayout.BeginArea(new Rect((Screen.width / 2) - 128, (Screen.height / 2) - 64,256,128), GUIContent.none,);
             if (Won == MyPlayer.Team)
             {
                 GUI.Label(new Rect((Screen.width / 2) - 256, (Screen.height / 8) - 16, 512, 32), "Your team won!", Skin.GetStyle("End"));
             }
             else
             {
                 //GUILayout.Label("Your team lost!");
                 
                 GUI.Label(new Rect((Screen.width / 2) - 256, (Screen.height / 8) - 16, 512, 32), "Your team lost!", Skin.GetStyle("End"));
             }
 
             if (Network.isServer)
             {
                 if (GUI.Button(new Rect((Screen.width / 2) - 256, (Screen.height / 8) + 128, 512, 32), "Restart", Skin.GetStyle("End")))
                 {
                     networkView.RPC("ResetEndGame", RPCMode.All);
                     networkView.RPC("Client_LoadMap", RPCMode.All, Settings.MapName, altprefix + 1);
                     
                     
                 }
             }
            // GUILayout.EndArea();
                 
         }
         //if(MatchedLoaded)
         //    if(GUILayout.Button("Leave"))
         //        Network.CloseConnection(Network.player,false);
         
     }
     
     [RPC]
     void Server_SpawnPlayer(NetworkPlayer Player, Vector3 Pos, Quaternion Rot){
             
         
         
         //if(FirstSpawn && SpawnPoints[numberSpawn].tag == MyPlayer.Team){
         //    networkView.RPC("Client_SpawnPlayer",RPCMode.All,Player,SpawnPoints[numberSpawn].transform.position,SpawnPoints[numberSpawn].transform.rotation);    
         //}else{
         /* if (ChoseDeploy == false)
          {
              int numberSpawn = Random.Range(0, SpawnPoints.Length);
              networkView.RPC("Client_SpawnPlayer", RPCMode.All, Player, SpawnPoints[numberSpawn].transform.position, SpawnPoints[numberSpawn].transform.rotation);
          }
          else
          */
         //if (MyPlayer.Team == "Sas")     
        // {
             //int numberSpawn = Random.Range(0, SpawnPointsGood.Length    
             networkView.RPC("Client_SpawnPlayer", RPCMode.All, Player, Pos + new Vector3(0,1.1f,0), Rot);
         //}
        // else
        // {
             //int numberSpawn = Random.Range(0, SpawnPointsBad.Length);
          //   networkView.RPC("Client_SpawnPlayer", RPCMode.All, Player, SpawnPointsBad[numberSpawn].transform.position, SpawnPointsBad[numberSpawn].transform.rotation);
         //}
         
         
         //}
     }
     [RPC]
     void Client_SetTeam(string team,string ThePlayerName){
         GetMPPlayer(ThePlayerName).Team = team;
         if (team == "Sas" && GameModeManager.Inst.Alim != null)
         {
             GameModeManager.Inst.Alim.SasPlayerLives.Add(new Lives(GetMPPlayer(ThePlayerName)));
         }
         else
         {
             GameModeManager.Inst.Alim.MqrPlayerLives.Add(new Lives(GetMPPlayer(ThePlayerName)));
         }
         Debug.Log("Added Lives");
     }
     [RPC]
     void Client_SpawnPlayer(NetworkPlayer Player, Vector3 Pos, Quaternion Rot){
         MultiplayerManager.GetMPPlayer(Player).PlayerIsAlive = true;
         if(Player == MyPlayer.PlayerNetwork){
             MyPlayer.Manager.ControllerTranform.position = Pos;
             MyPlayer.Manager.ControllerTranform.rotation = Rot;
             MyPlayer.Manager.networkView.RPC("Client_ImAlive", RPCMode.AllBuffered);
     //    }else{
                 
         }
     }
     
     void OnLevelWasLoaded(){
         //MatchedLoaded = true;
         
         
         if(Application.loadedLevelName == Settings.MapName){
             SpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
             SpawnPointsGood = GameObject.FindGameObjectsWithTag("SpawnPointAllies");
             SpawnPointsBad = GameObject.FindGameObjectsWithTag("SpawnPointAxis");    
             networkView.RPC("Client_ServerLoaded",RPCMode.AllBuffered);
             SceneManager = GameObject.Find("LevelManager").GetComponent<LevelManager>();
             //LoadingScreen.LS.DisableAll();
         }
 
         /*foreach(Camera cam in Camera.allCameras){
             if (cam.GetComponent<Color3Grading>())
             {
                 cam.gameObject.AddComponent<Color3Grading>();
             }
         }
          */
             
     }    
     
     [RPC]
     void Client_ServerLoaded(){
         MatchStarted = true;    
     }
     
     public static MpPlayer GetMPPlayer(NetworkPlayer Player){
         foreach(MpPlayer pl in MultiplayerManager.instance.PlayerList){
             if(pl.PlayerNetwork == Player)
                 return pl;
         }
         return null;
     }
     
     public static MpPlayer GetMPPlayer(string PlayerNamed){
         foreach(MpPlayer pl in MultiplayerManager.instance.PlayerList){
             if(pl.PlayerName == PlayerNamed)
                 return pl;
         }
         return null;
     }
 
     public static Team GetTeam(string TeamName)
     {
         foreach (Team t in instance.Settings.Teams)
         {
             if (t.Name == TeamName)
                 return t;
         }
         return null;
     }
 
     
     void SpawnMenu(){
         
             /*if(GUI.Button(new Rect(5,Screen.height-40,250,35),"Spawn"))
             {
                 
                 if(Network.isServer)
                     Server_SpawnPlayer(Network.player);
                 else
                     networkView.RPC("Server_SpawnPlayer",RPCMode.Server,Network.player);    
             }
              */
         if (!Finished)
         {
             GUILayout.BeginArea(new Rect(Screen.width - (Screen.width / 4), 0, Screen.width / 4, Screen.height));
             if (CurrentType == "Control Points")
             {
                 if (MyPlayer.Team == "Mqr")
                 {
                     if (GUILayout.Button("Deployment"))
                     {
                         int Spawn = Random.Range(0, SpawnPointsBad.Length);
                         Vector3 pos = SpawnPointsBad[Spawn].transform.position;
                         Quaternion rot = SpawnPointsBad[Spawn].transform.rotation;
                         if (Network.isServer)
                             Server_SpawnPlayer(Network.player, pos, rot);
                         else
                             networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);    
                     }
                 }
                 else
                 {
                     if (GUILayout.Button("Deployment"))
                     {
                         int Spawn = Random.Range(0, SpawnPointsGood.Length);
                         Vector3 pos = SpawnPointsGood[Spawn].transform.position;
                         Quaternion rot = SpawnPointsGood[Spawn].transform.rotation;
                         if (Network.isServer)
                             Server_SpawnPlayer(Network.player, pos, rot);
                         else
                             networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);    
                     }
                 }
                  
 
                 
                 foreach (ControlArea ca in GameModeManager.Inst.ControlPoints.Points)
                 {
                     if (ca.Team == MyPlayer.Team)
                     {
                         if (GUILayout.Button(ca.PointName))
                         {
                             int Spawn = Random.Range(0, ca.SpawnPoint.Spawns.Count);
                             Vector3 pos = ca.SpawnPoint.Spawns[Spawn].transform.position;
                             Quaternion rot = ca.SpawnPoint.Spawns[Spawn].transform.rotation;
                             if (Network.isServer)
                                 Server_SpawnPlayer(Network.player, pos, rot);
                             else
                                 networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);    
                         }
                     }
                 }
             }
             else if (CurrentType == "Team Deathmatch")
             {
                 if (GUILayout.Button("Deployment")){
                     int Spawn = Random.Range(0, GameModeManager.Inst.TeamDM.SpawnPoints.Spawns.Count);
                     Vector3 pos = GameModeManager.Inst.TeamDM.SpawnPoints.Spawns[Spawn].transform.position;
                     Quaternion rot = GameModeManager.Inst.TeamDM.SpawnPoints.Spawns[Spawn].transform.rotation;
                     if (Network.isServer)
                         Server_SpawnPlayer(Network.player, pos, rot);
                     else
                         networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);    
                 }
             }
             else if (CurrentType == "Planter")
             {
                 if (MyPlayer.Team == "Mqr")
                 {
                     // foreach (GameObject go in GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].SasSpawns.Spawns)
                     // {
                     if (GUILayout.Button(GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].MqrSpawns.Name))
                     {
                         int Spawn = Random.Range(0, GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].MqrSpawns.Spawns.Count);
                         Vector3 pos = GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].MqrSpawns.Spawns[Spawn].transform.position;
                         Quaternion rot = GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].MqrSpawns.Spawns[Spawn].transform.rotation;
                         if (Network.isServer)
                             Server_SpawnPlayer(Network.player, pos, rot);
                         else
                             networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);    
 
 
                     }
                     //  }
                 }
                 else
                 {
                     if (GUILayout.Button(GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].SasSpawns.Name))
                     {
                         int Spawn = Random.Range(0, GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].SasSpawns.Spawns.Count);
                         Vector3 pos = GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].SasSpawns.Spawns[Spawn].transform.position;
                         Quaternion rot = GameModeManager.Inst.Planter.Areas[GameModeManager.Inst.Planter.CurArea].SasSpawns.Spawns[Spawn].transform.rotation;
                         //Server_SpawnPlayer(Network.player, pos, rot);
                         if (Network.isServer)
                             Server_SpawnPlayer(Network.player, pos, rot);
                         else
                             networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);
                     }
                 }
 
             }
             else
             {
                 if (MyPlayer.Team == "Mqr")
                 {
                     if (GameModeManager.Inst.Alim.FindLivesFromOwner_Mqr(MyPlayer).LivesLeft > 0)
                     {
                         if (GUILayout.Button("Spawn"))
                         {
                             int Spawn = Random.Range(0, GameModeManager.Inst.Alim.MqrSpawns.Count);
                             Vector3 pos = GameModeManager.Inst.Alim.MqrSpawns[Spawn].transform.position;
                             Quaternion rot = GameModeManager.Inst.Alim.MqrSpawns[Spawn].transform.rotation;
                             if (Network.isServer)
                                 Server_SpawnPlayer(Network.player, pos, rot);
                             else
                                 networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);
                         }
                     }
                     else
                     {
                         if (GUILayout.Button("View Freecam"))
                         {
                             GameModeManager.Inst.Alim.FreeCam.SetActive(true);
                         }
                     }
                 }
                 else
                 {
                     if (GameModeManager.Inst.Alim.FindLivesFromOwner_Sas(MyPlayer).LivesLeft > 0)
                     {
                         if (GUILayout.Button("Spawn"))
                         {
                             int Spawn = Random.Range(0, GameModeManager.Inst.Alim.SasSpawns.Count);
                             Vector3 pos = GameModeManager.Inst.Alim.SasSpawns[Spawn].transform.position;
                             Quaternion rot = GameModeManager.Inst.Alim.SasSpawns[Spawn].transform.rotation;
                             if (Network.isServer)
                                 Server_SpawnPlayer(Network.player, pos, rot);
                             else
                                 networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player, pos, rot);
                         }
                     }
                     else
                     {
                         if (GUILayout.Button("View Freecam"))
                         {
                             GameModeManager.Inst.Alim.FreeCam.SetActive(true);
                         }
                     }
                 }
             }
 
             //if (GUILayout.Button("Spawn"))
             // {
             //    GameObject.Find("Main Camera").camera.enabled = false;
 
             //    if (Network.isServer)
             //         Server_SpawnPlayer(Network.player);
             //    else
             //        networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);    
             // }
             GUILayout.EndArea();
         }
     }
 
     /*void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         if (stream.isWriting)
         {
             
             stream.Serialize(ref Time);
         }
         else
         {
             stream.Serialize(ref Time);
             
         }
     }
      */
 
     [RPC]
     public void Client_UpdatePoop(NetworkPlayer id, bool Isalive, float health,string weap, NetworkPlayer hit)
     {
         MpPlayer player = MultiplayerManager.GetMPPlayer(id);
         player.Manager.ControllerTranform.GetComponent<BloodyScreen_SoReal>().HitAlpha += 1 * (player.PlayerHealth - health) * 0.01f;
         player.PlayerIsAlive = Isalive;
         player.PlayerHealth = health;
         player.Manager.LastShootBy = GetMPPlayer(hit);
         player.Manager.LastShooterName = GetMPPlayer(hit).PlayerName;
         player.Manager.LastShooterGun = weap;
         
     }
     
 }
 [System.Serializable]
 public class MpPlayer {
     public string PlayerName = "";
     public NetworkPlayer PlayerNetwork;
     public PlayerManager Manager;
     public float PlayerHealth = 100;
     public bool PlayerIsAlive;
     public int PlayerKills;
     public int PlayerDeaths;
     public int PlayerScore;
     public string Team;
     public int Level;
     public bool InVeh = false;
     public bool Spotted;
     public static MpPlayer none = new MpPlayer();
     //[HideInInspector]
    // public int MultiKillAmount;
 }
 [System.Serializable]
 public class RoomSettings{
     public string MapName;
     public string MapLoadName;
     public Team[] Teams;
     public string[] GameTypes;
     
     //public string ActualType;
 }
 
 [System.Serializable]
 public class Team
 {
     public string Name;
     public Color TeamColour = Color.red;
 }
 
 [System.Serializable]
 public class SpawnAreas
 {
     public string Name;
     public List<GameObject> Spawns = new List<GameObject>();
     public bool ShowInEditor;
     
 }
     
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by burkedrane · Aug 08, 2013 at 05:29 PM

Its not just ODD, it is wrong.

There should absolutely not be one set of owners on one client, a different set on another client, and a third on the host (which has them correct)

The network model is peer to peer, yet this is enforcing authoritative host.

The workaround isn't difficult, if you need a mapping of players to the objects they own, you can just use a buffered RPC and pass the real owner and allocated viewID yourself, but why have a convenience function like Network.Instantiate if it gets the owner wrong.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joeconstable97 · Aug 08, 2013 at 05:45 PM 0
Share

Thanks so much!

avatar image Jamora · Aug 08, 2013 at 06:40 PM 1
Share

The unity networking system is not by default a p2p model. It is a client-server model. Though you can set it up as a p2p - if you want to - by having the server be a playing client and maintaining a list of all connected players on all clients, like you said.

This answer gets it right.

A short quote from the unity networking documentation: " A fundamental idea is that of the relationship between the client [...] and the server " (emphasis in the original).

Due to the reasons in my answer, I still dare say that, by default, the server knows the real instantiators and the clients only know that the server is the owner of objects they have not instantiated themselves.

avatar image burkedrane · Aug 08, 2013 at 07:14 PM 0
Share

I don't know a game dev that would call it anything but peer to peer unless it enforces authoritative hosts. Obviously the messages are passed through the host. Raknet is built around the RakPeer interface and NPT, right? I'm sure you're just trying to be pedantic, but for what?

If you can instantiate on a client, and the ownership is different on each machine, then its wrong. Client 2 is told that Client 1's object is owned by the host, while the host doesn't think he owns that object. Any mapping attempts between objects and players on a client will fail unless you enforce your own host authority.

An invalid owner on the client would make more sense than yielding a wrong owner.

Joey, unless you require natpunchthru or Raknet's flow control (really nice for strea$$anonymous$$g large amounts of data), I'd take a look at uLink. We've shipped several games with it, and it greatly reduces the hair pulling.

avatar image joeconstable97 · Aug 08, 2013 at 07:19 PM 0
Share

Okay, will do :)

avatar image
0

Answer by Jamora · Aug 04, 2013 at 07:47 PM

I would assume that is how Unity works: All clients only know the server, and the server knows all clients. So it would be logical to have all NetworkInstantiates by clients owned by the server to all other clients but the instantiator. This way it can receive updates from the real owner and then relay the updates to the other clients (only owner can send data). Additionally any netviewView.isMine by a client will then return false on objects not owned by the client, which is how it should be like.

I dare say this behavior is by design.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joeconstable97 · Aug 05, 2013 at 10:17 AM 0
Share

Odd decision by Unity there. Anyway thanks alot :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

MultiPlayer - NetworkPlayer Event 2 Answers

Network view , ownership 1 Answer

Assigning the owner of networkviews manually 1 Answer

BroadcastMessage to Instantiated Object 1 Answer

Server 24/7 and NetworkID owner 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges