How to create a "Looping" Cast. C++

I used int16 because I didn’t need a value above 100 tries. I wasn’t aware of its limitations, thank you for telling me.

An example of a situation that needed this on my last project was a “house” and “floors” system.

  • They were two separate actors, the house would have all the logic while the floors would be just a volume that would encompass the whole floor that is assigned to it.
  • The main goal would be to hide and show the floors as needed.
    The “floors” would tend to load faster than the “house” and because of that they would simply not work (No crashes). So to avoid this I made a BP library that handles cast retries. It tries 50 times with 0.2 second intervals.

The C++ version uses Unreal’s timer handles. They are not C++ sleep functions they won’t make the code lock, they just get triggered, try to cast 50 times and if it fails it just prints out a message saying that “X” cast failed, and the game just keeps going.