Cogito, ergo sum
Legacy:Replication Examples/Emitter replication
Emitter replication example
This emitter is based on Spiral.uc emitter that is used in game to spawn those flares marking item pickup locations. This emitter allows to change the color of these flare at runtime by calling functions SetFirstColor(Color firstC) and SetSecondColor(Color secondC).
Note: This emitter works in UT2004.
#exec OBJ LOAD FILE=EpicParticles.utx //----------------------------------------------------------- // by Shadow_knight //----------------------------------------------------------- class ChangingEmitter extends Emitter; //here we will store colors that will be used by the emitter var color FirstColor; var color SecondColor; //We need to replicate the variables FirstColor and SecondColor to clients replication { reliable if(Role == Role_Authority) FirstColor, SecondColor; } //this function sets the FirstColor variable to desired value, it is simulated so it will set the FirstColor also on client simulated function SetFirstColor(Color firstC) { FirstColor = firstC; } //same as previous function except it will set SecondColor simulated function SetSecondColor(Color secondC) { SecondColor = secondC; } //This is our key function. This function is called on clients if the actor has set bNetNotify to true //Here we will set the emitter to use our color variables simulated function PostNetReceive() { Emitters[0].ColorScale[1].Color = FirstColor; Emitters[0].ColorScale[2].Color = SecondColor; } defaultproperties { //The SpriteEmitter object here is copy paste from original UT class Spiral.uc Begin Object Class=SpriteEmitter Name=SpriteEmitter2 UseColorScale=True ColorScale(0)=(Color=(B=255,G=255,R=255)) ColorScale(1)=(RelativeTime=0.200000,Color=(G=170,R=255)) ColorScale(2)=(RelativeTime=1.000000,Color=(G=217,R=255)) FadeOutStartTime=1.300000 FadeOut=True FadeInEndTime=0.250000 FadeIn=True MaxParticles=15 StartLocationShape=PTLS_Sphere SphereRadiusRange=(Min=16.000000,Max=16.000000) RevolutionsPerSecondRange=(Z=(Min=0.200000,Max=0.500000)) RevolutionScale(0)=(RelativeRevolution=(Z=2.000000)) RevolutionScale(1)=(RelativeTime=0.600000) RevolutionScale(2)=(RelativeTime=1.000000,RelativeRevolution=(Z=2.000000)) SpinsPerSecondRange=(X=(Max=4.000000)) StartSizeRange=(X=(Min=4.000000,Max=4.000000),Y=(Min=4.000000,Max=4.000000),Z=(Min=8.000000,Max=8.000000)) UniformSize=True Texture=Texture'EpicParticles.Flares.HotSpot' LifetimeRange=(Min=1.600000,Max=1.600000) StartVelocityRadialRange=(Min=-20.000000,Max=-20.000000) VelocityLossRange=(X=(Min=0.200000,Max=0.200000),Y=(Min=0.200000,Max=0.200000),Z=(Min=1.000000,Max=1.000000)) GetVelocityDirectionFrom=PTVD_AddRadial UseVelocityScale=True VelocityScale(0)=(RelativeVelocity=(X=2.000000,Y=2.000000,Z=2.000000)) VelocityScale(1)=(RelativeTime=0.600000) VelocityScale(2)=(RelativeTime=1.000000,RelativeVelocity=(X=-10.000000,Y=-10.000000,Z=-10.000000)) LowDetailFactor=+1.0 Name="SpriteEmitter7" End Object Emitters(0)=SpriteEmitter'SpriteEmitter2' bNoDelete=false bAlwaysRelevant=True bNetTemporary=False bHidden=False bNetNotify=True //this is important here, otherwise the function PostNetReceive() would not be called RemoteRole=ROLE_SimulatedProxy CullDistance=+2000.0 FirstColor=(R=255) //This will be default FirstColor for our emitter SecondColor=(R=255) //This will be default SecondColor for our emitter }
Discussion
Now, why we haven't set the Emitters[0].ColorScale[1].Color in functions SetFirstColor(Color firstC) and SetSecondColor(Color firstC) directly? This wouldn't work because these functions won't be replicated as long as the owner of the emitter wouldn't be some PlayerController class. On the other side, function PostNetReceive() is replicated always when bNetNotify is set to true.
It is possible to set also the other emitter values by creating the replicated variable and then setting it up in PostNetReceive() function.