- Home /
Late join Auth Server Instantiation - ViewID issues?
Walloftext.net
reviously in my development I had used the Network.Instantiate function to spawn my players. I also had incorporated a lobby that allowed players to set up and chat to other players before actually commencing gameplay. When I attempted to use this to allow late players to join I ran into issues with its buffered nature. So I set about coding my own instantiate system that allowed me to spawn and set up games for players whenever I wanted.
At the moment I have what I assumed to be a working method to capture store and update a newly connected player. When a player joins my server it asks to be updated on currently connected players and then requests to be spawned itself. From what I could understand from googling and trawling this website for answers i needed to allocate the View Id's like network.Instantiate on my own.
My understanding is limited but i figured i could allocate the ViewID to an array when a player requests to spawn (which works and is not buffered so as people join and as new ID's are allocated they are assigned and everything is sync'd and stored. My problem comes when i try to instantiate the current players for the newly joined player. I figured i could save the ViewID's of the players spawn the player objects and assign the correct ID to each player. The game would try to update that ID and hey presto. Unfortunately thats not the case. Despite the ID being the correct one and been assigned to the right player object it fails to update itself and throws update ID errors about its initial state being wrong.
I assume this is because i fail to attach it and i should use groups to stop the messages being updated for these players but i also figured atleast when it spawned and assigned the ID it would then begin to update it. However this is not the case.
I have to be missing something vital :/ but i cant gleem any more information from the documentation or from various partially appropriate questions.
This is essentially the management script on all players clients/the server that controls communication to the server and the spawning of playerobjects. Its paraphrased and rewrote so ignore spelling mistakes, caps errors and missing parameters and such.. focus on the principle of the code to late network instantiation instead of its debugging issues!
onnetworkplayerconnected(){
if(server){
spawnPlayer();
addToSpawnList();
}else{
networkView.RPC("SpawnConnectedPlayers",RPCMode.Server)
networkView.RPC("requestSpawn",RPCMode.Server)
}
}
@RPC
function spawnPlayer(Loc:Vector3, ViewID : NetworkViewID){
var go : GameObject = GameObject.Instantiate(PlayerGameObject,loc,Quaternion.identity);
go.networkView.viewID = ViewID;
}
@RPC
function requestSpawn(PlayerID : String, NP:NetworkPlayer){
if(CheckSpawnedList()){
viewID = networkView.AllocateViewID;
networkView.RPC("SpawnPlayer",RPCMode.All,GetSpawnPoint(),viewID);
addToSpawnList(PlayerID);
}
}
@RPC
function SpawnConnectedPlayers(NetworkPlayer,PlayerID){
for(var i : int; i<SpawnList.Length;i++){
if(SpawnList[i] is NotMe && NotNull){
networkView.RPC("SpawnPlayer",NetworkPlayer,GetSpawnPoint(),SpawnList[i].ViewID);
}
}
}
function addToSpawnList(PlayerID, NetworkPlayer, ViewID){
for(var i : int; i<SpawnList.Length;i++){
if(SpawnList[i].PlayerID == null){
SpawnList[i].PlayerID = PlayerID;
SpawnList[i].NetworkPlayer = NetworkPlayer;
SpawnList[i].ViewID = ViewID;
break;
}
}
}
`
What i know:
Late joining players update and appear for current players with no issues.
Current players are created and the network view assigned but the state messages sent are ignored from the clients owner on the new players game because of an initial state error?
All viewID's are correct on the late joined player when the client spawns the current players for them.
Your answer
Follow this Question
Related Questions
How do I GetComponent from a NetworkView? 0 Answers
UNET The clients can't see the game object 0 Answers
Network.Instantiate spawns multiple objects 2 Answers
SpawnWithCLientAuthority Issues... 0 Answers
[Command]-Function By Client is not called on Server 1 Answer