Networking HLAPI Spawning Objects

Hello,

I have been reading through the new networking manual and ran into a few pretty simple questions.
http://docs.unity3d.com/Manual/UNetSpawning.html

“there is a registration step that
clients have to perform; they must
call ClientScene.RegisterPrefab to
tell the system about the asset that
the client object will be created
from”

Lets say I want to call NetworkServer.Spawn(prefabHere); on the server…

  1. Is this the correct function to call?
  2. Do I need to register the prefab?
  3. If so do I use ClientScene.RegisterPrefab or another class/function?
  1. Yes, it is, and as you wrote, you can call it only on the server side.
  2. Only on the client-side as the documentation mentioned it.
  3. That function is what you looking for. :slight_smile:

If you don’t register the prefab on the client-side, it won’t be instantiated on the client.
And of course, your prefab has to have a NetworkIdentity component.

Salut!
My situation is:

void SvrExecGunFire()
{
    if (this.isServer)
        if (flagSvrGunFirePressed)
        {
            GameObject gobjProjectile =
                (GameObject)GameObject.Instantiate
                (
                    this.GetComponent<ArmourPerfData>().GunMainProjectilePrefab,
                    this.GunMuzzle.position,
                    this.GunMuzzle.rotation
                );
                Vector3 veloMuzzle =
                    this.GunMuzzle.TransformDirection(0, 10, this.GetComponent<ArmourPerfData>().GunMainMuzzleVeloMps);
                gobjProjectile.GetComponent<Rigidbody>().AddForce(veloMuzzle, ForceMode.VelocityChange);
                NetworkServer.Spawn(gobjProjectile);
                RpcUpdateGunFire();
        }
}

In this sample I added a projectile prefab to NetworkManager\SpawnInfo\RegisteredSpawnablePrefabs (which is quite inconvenient).
I changed parameters of gobjProjectile and I’m trying propagated this projectile to all clients on the arena.

So the question is: How can I pass parameters to gobj?

Because NetworkServer.Spawn() strips all modifications to the object, and all clients receive a zeroed copy.

And this robbery is contradicting to documentation http://docs.unity3d.com/Manual/UNetSpawning.html which specifies exactly the opposite: “When this code runs, the tree objects created on clients will have the correct value for numLeaves from the server.”