[BUG] AddOnScreenDebugMessage() Produces FVector to Change

Whenever I try to debug my FVector (being done inside a Tick()) using GEngine->AddOnScreenDebugMessage() my variable “FVector Velocity” gets modified, if I comment out the debug function, it returns to normal. Add it back in, the vector is modified again.

void UPSA25D_PhysicsComponent::CalcVelocity()
{
	//Velocity += (ReturnAcceleration() * FApp::GetDeltaTime());
	Velocity = (ReturnAcceleration());
	GEngine->AddOnScreenDebugMessage(-1, 0.02f, FColor::Green, *Velocity.ToString());
}

FVector UPSA25D_PhysicsComponent::ReturnAcceleration()
{
	FVector FinalAcceleration;

	if (Acceleration.Num() < 1)
		return FVector(0, 0, 0);

	for (int32 i = 0; i < Acceleration.Num(); i++)
	{

		FinalAcceleration += Acceleration[i];
	}

	return FinalAcceleration;
}

I’m adding Acceleration using W A S D to add to the Acceleration by 256 in a given direction.

Good Vector (no debugging)

bad vector (debugging w/ AddOnScreenDebugMessage)

Just to clarify. At no point am I adding any movement in the X direction. Only modifying the Z direction. Adding the Debugging automatically adds a random push in the X direction.

GEngine->AddOnScreenDebugMessage(-1, 0.02f, FColor::Green, *Velocity.ToString());

to

GEngine->AddOnScreenDebugMessage(-1, 0.02f, FColor::Green, Velocity.ToString());

Works temporarily. But switching my variable “FVector Gravity” to be debugged the same way just begins to produce the same effect.

GEngine->AddOnScreenDebugMessage(-1, .02f, FColor::Yellow, Gravity.ToString());

originally was using an asterick as well (*Gravity.ToString())

I take that back. It doesn’t work. It instead produces Z to = 36 until I mess with it, then it sets itself to 0. Pressing again resets it to Z = 36.

There’s no reason why AddOnScreenDebugMessage is changing your FVector, that doesn’t quite make sense to me. Try:

GEngine->AddOnScreenDebugMessage(-1, 0.02f, FColor::Green, ReturnAcceleration().ToString());

And see if the same thing happens.

Same results proceeded.Whenever the debug messages are on, they are definitely changing, while off they’re fine.

However, I did modify my logic a little and that seems to of fixed the issue (at least as far as I can tell) in that I am no longer adding up an Array of FVector’s to act as all my imposing forces to produce acceleration. Instead, I’m using a single FVector and modifying it directly and then using that, and the artifacts ar no longer appearing at this moment. So whether it was just poorly executed programming, or an actual bug I have worked around it for now.

But I couldn’t find any logic as to why adding the debug call would produce different results in the first place.

That was my thought exactly, I’m glad you’ve got it fixed. I’ve tried to re-create the bug but haven’t found anything out of the norm.

What I believe is the core issue (although not-understood as to why) was my logic chain followed as such:

Tick()
{
 AddGravity()
 CalculateVelocity()
 ClearAcceleration()
}

AddGravity() used AddAcceleration() downwards (or whatever direction gravity is currently at) every tick, CalculateVelocity() added up every Array Entry inside a TArray called Acceleration, then applied it to Velocity (with time modifications). After that, the frame would clear the Acceleration and the chain would repeat.

So adding to, adding up, and clearing a dynamic FVector array every frame things were getting jumpled. Yet, only when I used the OnScreenDebugMessage call. As DisplayAll showed everything working fine as far as I could tell.

The logic is still the same, however Acceleration is no longer an Array and just a single FVector. I’m going to hold off on marking this answered for a few days to see if it begins to crop up again.

Hi IrishKilter,

Sorry for the delay in responding to your post. I just wanted to check in and confirm that everything is working fine for you now. I tried to reproduce the results that you described, but was unable to do so.