I really hope modern games have outgrown the headache that is Unreal replication. This problem arises online:
I have a weapon that has a timer function in it. Every set amount of time (very short, ~ 0.1 seconds) TraceFire is called. It in turn calls ProcessTraceHit wich spawns an actor at the first colliding position. Functionally this is basically a laser sight. To keep things from getting too costly, one dot is spawned. If it is destroyed, another is spawned. As long as there is a dot, it should be moved (via SetLocation()) to the location I traced a few steps back. However, online, the first dot is created but never moved. It decays after a few seconds, and another is created. I store the dot in a variable: var LaserDot D;. My thought is that this variable is not being replicated, but it could be other things too.
So I'm looking for an expert opinion, and maybe a brief explanation of the replication involved here. Here is some code to help explain my work so far:
In the weapon:
The laser dot itself has almost no code:
I have a weapon that has a timer function in it. Every set amount of time (very short, ~ 0.1 seconds) TraceFire is called. It in turn calls ProcessTraceHit wich spawns an actor at the first colliding position. Functionally this is basically a laser sight. To keep things from getting too costly, one dot is spawned. If it is destroyed, another is spawned. As long as there is a dot, it should be moved (via SetLocation()) to the location I traced a few steps back. However, online, the first dot is created but never moved. It decays after a few seconds, and another is created. I store the dot in a variable: var LaserDot D;. My thought is that this variable is not being replicated, but it could be other things too.
So I'm looking for an expert opinion, and maybe a brief explanation of the replication involved here. Here is some code to help explain my work so far:
In the weapon:
Code:
var LaserDot LD;
simulated function Timer()
{
TraceFire(0.0);
}
function TraceFire( float Accuracy )
{
local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z;
local actor Other;
local Pawn PawnOwner;
PawnOwner = Pawn(Owner);
GetAxes(PawnOwner.ViewRotation,X,Y,Z);
StartTrace = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z;
AdjustedAim = PawnOwner.AdjustAim(100000, StartTrace, 2.5*AimError, False, False);
EndTrace = StartTrace + Accuracy * (FRand() - 0.5 )* Y * 100
+ Accuracy * (FRand() - 0.5 ) * Z * 100;
X = vector(AdjustedAim);
EndTrace += (10000 * X);
Other = PawnOwner.TraceShot(HitLocation,HitNormal,EndTrace,StartTrace);
ProcessTraceHit(Other, HitLocation, HitNormal, X,Y,Z);
}
function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
local LaserDot L;
if((LD == none) && (Pawn(Owner).Health > 0))
{
L = Spawn(class'LaserDot',,, HitLocation+HitNormal*9, Rotator(HitNormal));
L.RemoteRole = ROLE_SimulatedProxy;
L.SetOwner(Owner);
LD = L;
LD.SetOwner(Owner);
LD.RemoteRole = ROLE_SimulatedProxy;
}
else if(Pawn(Owner).Health < 0)
LD.Destroy();
else
LD.SetLocation(HitLocation+HitNormal*9);
}
The laser dot itself has almost no code:
Code:
simulated function Tick(float DeltaTime)
{
if(Owner == none)
Destroy();
}
Last edited: