- Home /
[UNET] Optimizing Commands
Hey, I'm currently working on an FPS and am optimizing my commands to minimize bandwidth consumption.
Is it safe to assume that EVERYTHING inside a command is run on the server (meaning traffic sent)?
If so, how would I instantiate a game object on the server as Commands cannot take GameObjects as input?
Here's an example (which doesn't work due to the reason above) :
void CreateMuzzleFlash() { Transform flash = null; if (isLocalPlayer && gun.isRaycast) { flash = Instantiate(muzzleFlash, flashPoint.transform.position, firePoint.transform.rotation) as Transform; flash.parent = gameObject.transform; } if (!isLocalPlayer && gun.isRaycast || isLocalPlayer && !gun.isRaycast) { flash = Instantiate(muzzleFlash, flashPoint.transform.position, firePoint.transform.rotation) as Transform; flash.parent = flashPointNetwork.transform; } if (flash != null) CmdMuzzleFlashing(flash); } [Command] void CmdMuzzleFlashing(Transform flash) { NetworkServer.Spawn(flash.gameObject); }
Now, I could put it all into one Command, but the aim here is to minimize network traffic.
Can NetworkServer.Spawn() be called outside of a Command?
Perhaps using the Index of the object is a viable alternative?
Sorry if this is a convoluted question, I'm just trying to wrap my head around UNET.
Thanks!