There’s a problem with how you solved it. You’re just moving the impact point, meaning the weapon range could end up being shorter or longer. The correct way would be to actually rotate the direction it’s firing in. You can do that easily by turing it into a Rotator, adding a random amount, and then back to a Vector.
SpreadAmount -= DeltaTime * 1;
if(SpreadAmount < 0) SpreadAmount = 0;
//In shoot code
FVector AimDir = GetAdjustedAim();
FVector StartTrace = GetCameraDamageStartLocation(AimDir);
RandomX = FMath::RandRange(-20, 20);
RandomY = FMath::RandRange(-20, 20);
RandomZ = FMath::RandRange(-20, 20);
FRotator AimRot = AimDir.Rotator();
RandomAimRot += FRotator(RandomX, RandomY, RandomZ) * SpreadAmount;
FVector EndTrace = (StartTrace) + (RandomAimRot.Vector() * WeaponRange);
SpreadAmount += 0.3;
if(SpreadAmount .> 1) SpreadAmount = 1;
One of those Randoms isn’t needed, since you don’t need the bullet to twist in a barrel roll, I just don’t remember which.
Bonus: I added a variable called SpreadAmount. It starts at 0% (no spread) and every time a bullet is fires the spread increases to 100%, then in the tick function it slowly goes back to 0%. Should help realism on a rapidfire weapon.