Download

Spawning emitter while running on a dedicated server

I am trying to get my game to spawn a particle effect when a bullet collides with an object. The particles do spawn when running in singleplayer, however no emitter is spawned when running on a dedicated server. If I test it as a listen server, the emitter only spawns on the host.


 // Trace from old position to new position and test for collision
 FHitResult HitResult(ForceInit);
 bool HitSuccess = GetWorld()->LineTraceSingle(HitResult, ActorLocation, NewActorLocation,
                                           ECC_Visibility, TraceParams);
 
 
 if (HitSuccess)
 {
     // Bullet hit something
     ClientNotifyHit(HitResult);
 
     Destroy();
     
 }

Then in the ClientNotifyHit


 void ATOBullet::ClientNotifyHit_Implementation(const FHitResult Hit)
 {
     FVector ParticleLoc = Hit.ImpactPoint + (Hit.ImpactNormal * FVector(32.f, 32.f, 32.f));
     UGameplayStatics::SpawnEmitterAtLocation(this, ImpactParticle, ParticleLoc, 
                                               Hit.ImpactNormal.Rotation());
 }
 

ImpactParticle is set in the Blueprint for the bullet.

My first guess would be your object is getting destroyed before the rpc actually goes through. Maby a better option would be to do a tear off at that point then destroy, allowing clients to just destroy it them-self’s after the emitter effect.

Thanks for the suggestion, I moved Destroy() to the ClientHitNotify but still no emitter spawn.

Hm, that is weird as it would “seem” from that code it should work, try removing the Destroy() entirely, just to test, as maby the destroy is being called to early and destroying the emitter as well, but do not take this as fact as i have not looked into how emitters are spawned, but if it is being parented to the bullet as its destroyed, i would assume that it it would also be destroyed.

Interesting…so I tried that, and the particles do now spawn but don’t die. Seems to be working now, what I did was change the WorldContextObject argument in SpawnEmitterAtLocation from “this” to GetWorld(). Thanks for the help

Glad to hear you figured it out!

Sadly, I wasn’t testing it properly. Particles are only spawning on the host of a listen server, and not on clients connected to a dedicated server. One thing I did notice is marking a method as a “Client” callback will only call on the client owning the pawn. So I tried changing it to “NetMulticast” however no avail. After changing the argument to “GetWorld” as I mentioned before, I tried removing the Destroy method call…but still not working. I don’t understand why this isn’t working. :frowning:

EDIT: Looking at the ShooterGame example, looks like they spawn an actor, then spawn the emitter inside that actor and use it as the WorldContextObject. I wonder if there is some weird shenanigans going on in the background where GetWorld() is not totally valid when running on dedicated servers.

EDIT 2: I don’t have a single clue as to why this is not working. I went through all the work of creating a special “ImpactEffect” actor just like the ShooterGame example, and it’s still not working at all. I am completely lost at this point :mad:

EDIT3: -______- Woke up this morning, thought “HMM MAYBE THE ACTORS ARENT BEING REPLICATED”. Bam. It works. I feel dumb.