- Home /
Getting Reference to Player Objects at Network Game
I have some scripts at my network game how call the player Objects in theyer Start() functions. The problem is how i guss that the player is spawned at network after the scean start funcions are called so i get errors because the Player dont exist and the scripts gett NullPointer. How can i fix that ?
I guss i can just put this:
void Awake() {
gameObject.SetActive(false);
}
in every script that uses the Player and set them to active from the Player Start() function but is there a better way to do this?
Answer by TheSorm · May 05, 2016 at 02:29 PM
Found a good way by my self :)
public override void OnClientConnect(NetworkConnection conn) {
ClientScene.Ready(conn);
Object[] allObjects = Resources.FindObjectsOfTypeAll(typeof(GameObject));
foreach (GameObject go in allObjects) {
if (go.tag != "NetworkPlayer") {
go.SetActive(false);
}
}
ClientScene.AddPlayer(0);
foreach (GameObject go in allObjects) {
go.SetActive(true);
}
}
Id like to ask where do you put this script? if i put it on an ingame object it just disappears and the script is not working
@TheSorm, Although I was looking for an answer to a different problem, this post of yours from a few years ago led me to the solution I needed. Thanks