Using an assert (check) if two of the same actors have overlapping UBoxComponents on BeginPlay() in C++

Yes check and ensure should only trigger if their condition is false. I use asserts a lot as well since they allow you to check for any unexpected mistakes in code or when you setup specific objects. Plus you get automatic breakpoints when they are violated and you’re running with a debugger attached.

Since you are only checking for == ALocation::StaticClass() this means all overlaps must be other instances of ALocation. If your instance overlaps anything other than that the check should trigger. I think you have the condition reversed, you want the assert to fail (condition being false) whenever the overlap is another ALocation. So it should be checkf(!overlaps.OverlapInfo.GetComponent()->GetOwner()->IsA(ALocation::StaticClass()), ...);. This allows anything to overlap the ALocation unless it is another ALocation or derived from ALocation. You can also use overlaps.OverlapInfo.GetComponent()->GetOwner()->GetClass()->IsChildOf() instead of IsA.

Since in your case the message reads like a non-critical issue I’d also like to recommend the “map check for errors”. You could implement that in your ALocation class. You should be able to attach the actor instance(s) to the error message which allows you to directly link to the actor in the level.

1 Like