Respawn with arrays

I have a Script (GameManager) when after starting the game he selects a random Prefab player from a string


[SerializeField] private Transform[] _spawns;
public string[] CarsPlayerList;

Public void CreatePlayer(){

PhotonNetwork.Instantiate(CarsPlayerList[UnityEngine.Random.Range(0, CarsPlayerList.Length)], _spawns[Random.Range(0, _spawns.Length)].position, Quaternion.identity);


My second Script (CarController) has a void called Kill, the goal is that when I press the BackSpace button, the player is destroyed (by photonNetwork.destroy) and CarController calls GameManager CreatePlayer, but when it calls void to instantiate, the message appears that a new prefab cannot be instantiated because it is null


void Kill()
if (photonView.IsMine)
if (Input.GetKeyDown(KeyCode.Backspace))

Unity Mensage

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.Instantiate[T] (T original) (at <cfc1ad890650411e946cff2e6f276711>:0)
GameManager.CreatePlayer() (at Assets/Script/GameManager.cs:83)
GameManager.AddPlayer() (at Assets/Script/GameManager.cs:58)

the AddPlayer() that unity mentions is this one

public void AddPlayer()
if (PlayerInGame== PhotonNetwork.PlayerList.Length)

I suppose it's a logic error I created because as it gets instantiated via a string it gives an error with player.length of photonNetwork... but how does it respawn via a string after it dies then?


This discussion has been closed.