Download

How do I replicate the projectile in the FirstPerson template?


	/** Fires a projectile. */
	void OnFire();
	UFUNCTION(Reliable, Server, WithValidation)
	void ServerOnFire();
	void ServerOnFire_Implementation();
	bool ServerOnFire_Validate();



void AShooterCharacter::OnFire()
{ 
	ServerOnFire();
}
void AShooterCharacter::ServerOnFire_Implementation()
{
	// try and fire a projectile
	if (ProjectileClass != NULL)
	{
		const FRotator SpawnRotation = GetControlRotation();
		// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
		const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);

		UWorld* const World = GetWorld();
		if (World != NULL)
		{
			// spawn the projectile at the muzzle
			FActorSpawnParameters Param;
			Param.Instigator = this;
			AShooterProjectile* Proj = World->SpawnActor<AShooterProjectile>(ProjectileClass, SpawnLocation, SpawnRotation,Param);
			Proj->SetReplicates(true);
		}
	}

}

bool AShooterCharacter::ServerOnFire_Validate()
{
	return true;
}

The problem is it is still only visible on the owning client and I am not sure why. I have also checked Replicate, Replicate Movement, On Net Load and Always relevant but I still don’t see anything on the other clients.

What else do I need to do?

Okay it works now. The problem was that the editor just didn’t hot reload anymore. I just restarted the editor and everything is working.

How can something like this happen?