Particles syncing on the Unity Network
Hello there, I've got a trouble to sync particles in Unity Network system. How can I see it on client when emitting them on host and so on? Any ideas and solution are appreciated please :)
Answer by tcz8 · Sep 13, 2020 at 08:32 PM
I'm going to answer this question for posterity.
Like everything else in Unity, particles wont sync over the network just because you want them to (some "network enabled" components do but they are rare and deprecated with the old UNET). So, when you press "F" to emit your particles, you need to send a signal over the network to tell the "other side" to fire a particle.
In "pseudo code" you have to do something like this:
void EmitParticle() {
particleSystem.Emit(); // Launch your particle as usual
If (isOnlineGame) { // Tell network clients to launch particles
SendNetworkEventToEmitParticles();
}
}
Unfortunatly I can't be clearer about SendNetworkEventToEmitParticles() cause it changes depending on which multiplayer solution you are using (Unet, Bolt, ForgeNetworking, etc.) and how you implemented it in your game.
On the remote side of the connection you also need to have code in place to receive those network messages, interpret them and then act accordingly. In this case, emit particles (taking care not to send them again on the network or you will end up with an endless loop). This is pretty much the same for everything you want to sync over the network, firing a weapon, changing the weather, loading a map, changing which song is playing, etc.
Also, to be clear, the idea is not to replicate every single particle over the network but only to tell remote entities to fire their particles when needed. ie.: When dealing with bullets you can include in your message extra info like the target that was hit so you can properly "orient" your particle system before firing but beside that don't try to make it perfect. Remember that a game is all smokes and mirrors and over the network there is A LOT of smoke. FYI in this "bullet" case, synchronized bullets should never apply damage, it is only there for the show. Applying actual damage should be processed locally (like in a single player game) and then you send a damage event over the network.
Implementing multiplayer is one of the most complex part of game development. This is not the time to skip the manual. This is coming form a guy that doesn't like to RTFM. If you don't do it all you are doing is wasting your time and will end up rewriting your implementation multiple times before it starts working "semi" correctly and even then you will end up in the manual.
Good luck!
Answer by karl_jones · Oct 19, 2015 at 12:58 PM
You should have a ParticleSystem on both sides, then If you want to ensure that both sides see the same particle effect set the random seed to be the same (none zero) value on all clients. http://docs.unity3d.com/ScriptReference/ParticleSystem-randomSeed.html.
I've got ParticleSystem on both sides. I've created a GameObject child on my PlayerPrefab called Emitter and it has ParticleSystem attached to it. OnStartLocalPlayer I SetActive(true) to the Emitter and I'm using F key to Emit one particle for a test and it works only for LocalPlayer, on the other side I don't see it being emited. I want to use particles as projectiles, is it possible? And do I need to have them attached all the time to see it being emitted on the other player? Because I want to add particle emitter only to those players who "learn" it.
Answer by Chom1czek · Oct 19, 2015 at 03:58 PM
Bump anyone? Particles only work when they are set "Play On Awake" but when I want to emit it runtime it doesn't work so I guess I must emit it wrong. I am using
void Update()
{
if(isLocalPlayer)
{
if(Input.GetKeyDown(Keycode.F))
{
particleSystem.Emit(1);
}
}
}
I think it must be a problem but how to do it so that clients can see it?
Answer by OJazem · Apr 10, 2018 at 01:34 PM
Hey bro. did you manage to get it work? I am stuck with the same issue.
Your answer
Follow this Question
Related Questions
How do i spawn particles over network for everyone too see in UNET? 1 Answer
particle collision events networking 0 Answers
Lerping to Smooth Network Movement 0 Answers
Photon Weapon synchronize View Help Please 0 Answers
Need some help with networking, Object reference not set to an instance of an object. 0 Answers