[UNET] Spawn object on server BUT delete on your client
I have a Game Object that I instantiate on a client and spawn on the server.
Is there a way to then immediately remove it from the client that spawned it?
I have tried using 'Destroy()' but it seems to destroy it from the networked clients (which is weird)
If i try disabling the attached renderers to make it 'invisible', it still appears:
Here is the code that accesses the object:
[Command]
void CmdMuzzleFlashing()
{
Transform networkFlash = null;
// Network flash
networkFlash = Instantiate(muzzleFlash, flashPointNetwork.transform.position, flashPointNetwork.transform.rotation) as Transform;
networkFlash.name = "Network Flash";
// Spawn networked flash (local one is only for local)
networkFlash.GetComponent<ServerSpawnObject>().SpawnObject(networkFlash, "Network Flash");
// Disable the network flash components
if (gun.isRaycast)
ClientDisableFlash(networkFlash); // Disables the flash on the client
}
ServerSpawnObject.SpawnObject() just parents the flash to the first parameter, then renames to second, and finally runs NetworkServer.Spawn().
ClientDisableFlash:
[Client]
void ClientDisableFlash(Transform networkFlash)
{
networkFlash.gameObject.GetComponent<EllipsoidParticleEmitter>().enabled = false;
networkFlash.gameObject.GetComponent<ParticleRenderer>().enabled = false;
}
Any help would be greatly appreciated!
Thanks!
Answer by ykaradayi · Oct 11, 2017 at 06:11 AM
Did you ever figure this out? I'm trying to solve the same exact problem now..!
Your answer
Follow this Question
Related Questions
Client Spawning Player Objects 0 Answers
Problem with instantiating and declaring objects in Netcode on client 0 Answers
Unet - similar spawn functions acting different, client scale not transferring 1 Answer
Spawning GameObject on network, locally change it only on the client that spawned it. 0 Answers
Networking - How do i spawn an object with client authority? 1 Answer