0

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);
}

2 Answers2

1

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...

0

Ok first of I dont understand Unet compleltly but I got the same problems as yours here is what I did to debug it and try the following: 1- Make sure the projectile prefabs are added to NetworkManager script 2- In Your command use the hasAuthority bool check and use networkspawn inside if true and false. 3- From Your Command call a Client rpc and use NetworkSpawn there also 4- Use NetworkSpawnwithClientAuthority(this.gameobject) Let me know if these worked or not. Nonethless in Unity Docs the networkSpawn From command function should work on both the host and client but it always never seems to work first time but sometimes it does .

LumbusterTick
  • 1,067
  • 10
  • 21
  • "In Your command use the hasAuthority bool check and use networkspawn inside if true and false." Wait, do I use it whether it is false or not? Or did you mean to just say true? Also, would I use NetworkServer.SpawnWithClientAuthority() in the Rpc or in the command? – user2975229 Apr 20 '16 at 20:32
  • use in both , true and false , if it doesnt works use spawnwithclientauthority in command function , basically try all combinations – LumbusterTick Apr 21 '16 at 11:19