OnActorBeginOverlap is called in the middle of Tick

I’ve got following setup: squad of units, units are updated by the squad directly (not by their Tick) in the loop, units can take damage (i.e. from OnActorBeginOverlap with hazards).

And seems like unit’s OnActorBeginOverlap can be called right in the middle of the squad’s Tick method! I.e. I run for loop in the squad over the units, then OnActorBeginOverlap is called inside the loop on some iteration, unit takes damage, killed and removed from the list, my loop crashes because I was iterating over that list!

I was under impression that everything runs on the same thread. But seems like it doesn’t? Can OnActorBeginOverlap be in sync with at least Tick? Are all physics functions can be called anytime?

p.s. OnActorBeginOverlap is called from blueprints (which calls C++ apply damage function), while for loop is checked inside the C++ Tick.

You are insanely accurate!! Many thanks!

There is a function in UPrimitiveComponent called UpdateOverlaps

	virtual void UpdateOverlaps(TArray<FOverlapInfo> const* NewPendingOverlaps=nullptr, bool bDoNotifies=true, const TArray<FOverlapInfo>* OverlapsAtEndLocation=nullptr) override;

which calls checks for overlap changes and calls the appropriate events. This is called by functions such set setting actor location and scale

void USceneComponent::SetRelativeScale3D(FVector NewScale3D)
{

(skipped some code)

		if (IsRegistered())
		{
			if (!IsDeferringMovementUpdates())
			{
				UpdateOverlaps();
			}

My guess would be that somewhere in the tick function you make a call to set transform on an actor which calls through to the update overlaps function. To prove this is the case place a breakpoint in the OnActorBeginOverlap function and look at the call stack. It should eventually lead back to your tick function