[RESOLVED] PhotonNetwork.Instantiate() fails with no error

Options
I'm trying to instantiate a rocket projectile in my game with PhotonNetwork.Instantiate, but nothing happens. No rocket is spawned, no errors generated, nothing. I'm not sure how to troubleshoot this. Here is my relevant code.
GameObject bottleRocket;

void fireRocket(Vector3 bottleRocketStart, Quaternion bottleRocketRot)
    {

        GetComponent<PhotonView>().RPC("fireRocket_RPC", PhotonTargets.All, transform.position, Quaternion.identity, nm.teamID);

        //bottleRocket.GetComponent<Rigidbody>().AddForce(bottleRocket.transform.forward * rocketForce);
        //currentItemSprite = null;
        //GetComponent<GetItem>().currentItem = "";
    }

    [RPC]
    void fireRocket_RPC(Vector3 bottleRocketStart, Quaternion bottleRocketRot, int teamID)
    {
        bottleRocket = (GameObject)PhotonNetwork.Instantiate("BottleRocket", bottleRocketStart, bottleRocketRot, teamID);
        Debug.Log("After instantiation");
        // NullReferenceException here
        Debug.Log("Spawned bottle rocket position: " + bottleRocket.transform.position);
    }

With no errors or warnings, or anything, it's quite difficult to troubleshoot. Are there any other ways for me to troubleshoot exactly why my Instantiate line does absolutely nothing?

Comments

  • Tobias
    Options
    Is "After instantiation" logged? Please log bottleRocket, without referring to it's transform.
    Does the prefab exist in a Resources folder? Does it have a PhotonView?

    Aside from that: You should not network instantiate bullets/rockets. You can create them on each client and get rid of them locally when they hit something. It's rare you need to sync the position of bullets. They are too short-lived to network instantiate.
  • carnivoris
    Options
    "After Instantiation" is indeed logged. The prefab exists and has a photonview. I changed Debug.Log("Spawned bottle rocket position: " + bottleRocket.transform.position); to Debug.Log("Spawned bottle rocket position: " + bottleRocket); and it no longer throws an error, however, the bottleRocket variable is empty.

    As for the network instantiation, I actually need to keep track of who fired the rocket and the teamID makes that easy. However, I do want to ask how I'd create them on each client without using PhotonNetwork.Instantiate?
  • carnivoris
    Options
    I got it working. I had an issue with Instantiate because my prefab shared the name of the sprite in the Resources folder.
    [RPC]
        void fireRocket_RPC(Vector3 bottleRocketStart, Quaternion bottleRocketRot, int teamID)
        {
            bottleRocket = (GameObject)Instantiate(Resources.Load("BottleRocketProjectile"), new Vector3(bottleRocketStart.x, bottleRocketStart.y+1), bottleRocketRot);
        }
    

    I renamed my projectile prefab and now this code works.