Spawning Particle Effect on Server is Not Replicating to Clients

I’m building a co-op game and I’m trying to ensure that there are some tasks in the game that are achievable together. One of those tasks is lighting a fire. However, I’m having problems replicating the fire to the clients.

When a character goes to use an item. The particle effect doesn’t spawn on his screen or any of the other clients.

3d1ce397429fbd39facbc78e74c3d66a09db4bdb.jpeg

However, it is spawning on what I’m assuming is the server since it’s the main window in the Unreal Engine editor.

//ShooterCharacter.h


	UFUNCTION(reliable, server, WithValidation)
	void UseItem(); 

//ShooterCharacter.cpp


    void AShooterCharacter::UseItem_Implementation()
    {
    	if (Role < ROLE_Authority)
    	{
    		return;
    	}
    
    	//Code removed that gets the overlapping actors and loops through them

    		AUsableItem* const TestPickup = Cast<AUsableItem>(CollectedActors[iCollected]);
    	        if (TestPickup && !TestPickup->isActive)
    		{
    			TestPickup->isActive = true;
    			TestPickup->UseTheItem();
    		}
    	}
    }

//HiddenFire.h


 class SHOOTERGAME_API AHiddenFire : public AUsableItem
    .
    .
    .
    
    public:
	  virtual void UseTheItem() override;

	  UPROPERTY(EditDefaultsOnly, Category = "Particle System")
	  UParticleSystem* FireSpawnFX;

//HiddenFire.cpp


void AHiddenFire::UseTheItem()
    {
          //This code also does not work. Validated its not just particle effects. 
    		//FVector NewLocation = this->GetActorLocation() + FVector(0, 0, 300.0f);
    		//this->SetActorLocation(NewLocation);
    
    		UGameplayStatics::SpawnEmitterAtLocation(this, FireSpawnFX, GetActorLocation(), GetActorRotation());
    	}
    }

I have also tried multicast. I set the UseItem to Netmulticast and then removed the if (Role < ROLE_Authority) code from the UseItem_Implementation and it worked on just the client that called it. If I left the if (Role < ROLE_Authority) in there, it was never called at all
and spawned on no clients.

Any help would be GREATLY appreciated. Even pointing me to a particular location in an example project would be helpful. Thank you for your time.

You don’t want to spawn particles on the server, it’s just a waste. You’d be better off just having a replicated property that says its lit and then spawns the effect.



UPROPERTY(EditAnywhere, ReplicatedUsing=OnLitChanged)
bool IsLit;

void OnLitChanged()
{
   if (IsLit) // Spawn the particle, otherwise clean it up
   //...
}


Thank you so much Matt. I’ll try this out asap. What if I wanted to move an item? Same technique?

Yup. /5char

Thanks Matt! Got it working with a few tweaks. It looks like ReplicatedUsing is only called on clients? So I had to tweak it a little to spawn on the server in addition to the clients. Can’t tell you how much I appreciated this.