Search code examples
c#unity-game-engineunity3d-unet

UNET: Differences in running with Unity Editor and application


I'm trying to figure out what is causing the following difference in errors when using UNET:

I am running my project in the editor and in application form at the same time to test the multiplayer functionality. The functionality I am testing is projectile creation/spawning. If I make the editor the host and the application the client, only the host can see the projectiles. However, when I make the editor the client and the application the host, both players are able to see the projectiles.

This is where it gets odder: no matter what combination I use when running it on two applications, instead of one application and the editor, only the host can see the projectiles.

Why is this specific combination working, and how can I make it work for any setup?

Here is the spawning code; not sure if it is the issue:

[Command]
public void CmdFireProjectile(Quaternion cA, Vector3 tF, string pN) {
    GameObject projPrefab = Projectile.getProjectilePrefab(pN);
    GameObject proj = (GameObject)Instantiate(projPrefab, new Vector3(transform.position.x, transform.position.y + .4f, transform.position.z) + tF, cA);
    proj.GetComponent<Projectile>().setSource(this);
    NetworkServer.Spawn(proj);
}

Solution

  • So I figured it out: The class that registers the projectile prefabs to be accessed was set to only exist on the server. So essentially, the clients tried to create projectiles, but they didn't find any prefabs. Not sure why it specifically worked when run in the Unity editor though...