Unreal Engine 5 Crashes when I add a for loop

Hello, I enrolled in Unreal Engine 5 C++ Developer: Learn C++ & Make Video Games course couple days ago and things were going well. Today I was practicing by myself and I thought about creating a platform which draws circles. When I tried to do that I added a for loop and clicked to play button, UE5 didn’t repy at all and freezed. What is wrong? I think my loop is not having any mistakes. My .h and .cpp codes are down below. Thanks.


Ekran görüntüsü 2023-12-02 160934

You have an infinite loop as your condition for it is just 10 which will be converted to bool; non-zero values will be converted to true so you loop endlessly. You should have counter < 10 there.

With that said, that is effectively just

firstVector.Y = firstVector.Y + 10;
firstVector.X = firstVector.X + 10;

because that entire loop will execute before the frame is rendered.


On a side note counter should be declared in the loop i.e.

for (int32 counter = 0; ...; ...)

- C++ Core Guidelines
There’s also compound assignment operators where x = x + ... can be written x += ..., and for the specific case of + 1, ++x.

Thank you so much. I completely forgot about that comparing.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.