Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

uLink Instantiate not Creating Proxy Prefab on Joining Client

Discussion in 'Scripting' started by owiegand, Sep 30, 2014.

  1. owiegand

    owiegand

    Joined:
    Jan 20, 2014
    Posts:
    17
    I have already posted this in uLink's forums, but haven't got a response yet. I was hoping that someone here might have the solution to my issue. Currently I have the problem where a second connected player can't see the first. Here is the scenario :
    1) Player A Connects To The Server and is Instantiated
    2) Player B Connects To The Server (After Player A) and is Instantiated
    While both players are on created on the server correctly, Player B never creates a proxy for Player A on his local machine. As a result player B can never see player A.

    Here is the code I am using to spawn the player. The extra code is so I can change the players state from "Alive", "Dead", or "Spawn". This controls whether the player is visible or not. I do this instead of destroying the player each death . This script is run on a authoritative server and the method is called by an RPC from the player.

    Code (CSharp):
    1. void SpawnMyPlayer(uLink.NetworkPlayer player, string location, uLink.NetworkMessageInfo info){
    2.    
    3.         GetRandomSpawnPoint (location);
    4.  
    5.         //This Will Find Our Player or Create Our Player
    6.         GameObject OurPlayer = null;
    7.         bool FoundPlayer = false;
    8.         foreach(SpawnerList datapoint in SpawnerListData)
    9.         {
    10.             //Cycles Through All The Data To Find The Player We Want To Move and Turn on
    11.             if(player.id == datapoint.PlayerID){
    12.                 //We Are The Same Player That is on File
    13.                 OurPlayer = datapoint.SpawnedGameObject;
    14.                 FoundPlayer = true;
    15.             }
    16.             if(FoundPlayer){
    17.                 break;
    18.             }
    19.         }
    20.        
    21.         if (!FoundPlayer) {
    22.             //Debug.LogError("We Couldn't Find A Player That Matches");
    23.  
    24.             //Since We Dont Have a  Player Spawned Yet. Lets Create one.
    25.             GameObject instantiatedPlayer;
    26.             instantiatedPlayer = uLink.Network.Instantiate(player, proxyPrefab, ownerPrefab, creatorPrefab, selectedSpawnLocation.transform.position, selectedSpawnLocation.transform.rotation, 0);
    27.            
    28.             //Set The Player State. The Player Should Be Set To Alive
    29.             instantiatedPlayer.GetComponent ().ChangePlayerState ("Alive");
    30.            
    31.  
    32.             int PlayerID = player.id;
    33.             //We Then Add The Player And View ID The SpawnerDataList
    34.             SpawnerListData.Add (new SpawnerList(instantiatedPlayer, PlayerID));
    35.            
    36.             //Set The Players Team
    37.             string teamid = AssignTeam ();
    38.             //Debug.Log (teamid);
    39.             instantiatedPlayer.GetComponent ().SetTeam(teamid);
    40.  
    41.  
    42.  
    43.         } else {
    44.             //Player Found
    45.             //Move The Player To The Selected Spawn Location
    46.             OurPlayer.GetComponent().MovePlayer(selectedSpawnLocation.transform.position);
    47.            
    48.        
    49.             //Set The Player To Alive
    50.             OurPlayer.GetComponent ().ChangePlayerState ("Alive");
    51.             //This Resets The Values in Player Damage. We Will Need To Reset All Values
    52.             OurPlayer.GetComponent().ResetValues();
    53.         }
    54.     }
    55.  
    56.  
    57. [RPC]
    58. public void ClickedTheDeployButton(string location ,uLink.NetworkMessageInfo info){
    59.     uLink.NetworkPlayer player = info.sender;
    60.         SpawnMyPlayer (player,location, info);
    61.     //Debug.Log ("Calling on The Server!");
    62. }
    Any help would be great appreciated!