My function only works IF i use a UELOG in the middle of it.
So its super weird.
I found this out because i was trying to debug it, and when i debug it using UELOG, everything works fine.
Why would using a UELOG make things suddenly work, and not using make things not work?
I tried all kinds of things to understand what is happening. Im using visual studio and UE4.
Additionally this is quite a problem because how can i debug things, if they work when debugging, but dont work when not debugging?
Should i try to rebuild / generate visual studio project files?
What should i do?
Here is someone with a similar problem:
Full code, sorry for the length:
void UMeleeComponent::MoveInstancesByCheckpoints(float delta) {
FVector V;
FTransform T;
float speed = 60.f; //must get it from the data table structure of the main actor.
int32 inst;
FVector CurCheckpoint;
for (int32 i = MovingUnits.Num() - 1; i >= 0; i--)
{
inst = MovingUnits[i];
V.X = MainBatOwner->GetInstanceCustomDataValue(OwnerISM, inst, 5);
V.Y = MainBatOwner->GetInstanceCustomDataValue(OwnerISM, inst, 6);
CurCheckpoint = CurCheckpoints[i];
//GEngine->AddOnScreenDebugMessage(-1, 0.5f, FColor::Magenta," Next Checkpoint: " + FString::FromInt(inst));
UE_LOG(LogTemp, Log, TEXT(" instance loc: %s"), *CurCheckpoint.ToString());
//using one of these 2 logs will fix the function misteriously.
V = FMath::VInterpConstantTo(V, CurCheckpoint, g_DeltaTime, speed);
OwnerISM->SetCustomDataValue(inst, 5, V.X, false);
OwnerISM->SetCustomDataValue(inst, 6, V.Y, false);
if (V.Equals(CurCheckpoint, 0.001)) {
if (MovingUnits.Num() != FutureCheckpoints.Num()) {
UE_LOG(LogTemp, Warning, TEXT("ActiveCheckpointsIndex size: %d"), ActiveCheckpointsIndex.Num());
}
int32 c_index = ActiveCheckpointsIndex[inst];
ActiveCheckpointsIndex[inst]++;
if (!FutureCheckpoints.Contains(inst))
goto RemoveFromMovingUnits;
if (c_index < FutureCheckpoints[inst].CheckpointLocations.Num()) {
CurCheckpoints[i] = FutureCheckpoints[inst].CheckpointLocations[c_index];
CurCheckpoints[i], CurCheckpoint); //this also works but was bugging dont know why.
FTransform T_Rotate;
OwnerISM->GetInstanceTransform(inst, T_Rotate, true);
FRotator newrot = (CurCheckpoints[i] - CurCheckpoint).Rotation();
T_Rotate.SetRotation(FQuat(newrot));
OwnerISM->UpdateInstanceTransform(inst, T_Rotate, true, false, false);
}
else {
RemoveFromMovingUnits:
MovingUnits.RemoveSingleSwap(inst);
CurCheckpoints.RemoveSingleSwap(V);
ActiveCheckpointsIndex.Remove(inst);
FutureCheckpoints.Remove(inst);
MainBatOwner->Restore_WPO_Position_S_Safe(OwnerISM, inst);
switch (MainBatOwner->UnitState[inst]) {
case Attack:
FindEnemyToEngage(inst);
break;
}
}
//}
}
}
OwnerISM->MarkRenderStateDirty();
}