How can I check if something is STILL WITHIN a trigger volume?

I know about “Begin Overlap” and “End Overlap”…but what I REALLY need is to know if something is STILL within the bounds of the trigger volume after it’s already been overlapped.

I would make an array: add an object on “Begin Overlap” and subtract the same object on “End Overlap”. This will give you an array of objects overlapping the volume.

You could just use a variable with the begin overlap and end overlap functions.

47931-overlap.png

This is an alternative solution that may or may not be better for you, based on the situation you are dealing with, but the engine does have shape traces where you sweep through a particular area of space and the trace informs you of whether you have hit a specific type of object within that space. Running this every tick would be much more costly than the “use a variable/array on begin/end overlap” suggestions.

https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html#shapetraces

It’s a shame that a so called “NEXT-GENERATION” engine like Unreal Engine 4 doesn’t have something that even Gold Source do. But hey, we have PBR -.-

And yes, I know about get overlapping actors. Is not the same.

Actors and Primitive Components have GetOverlappingActors to check for other actors that are overlapping your actor:C++ doc and Blueprint node.

So you want something like TriggerVolume.GetOverlappingActors().Find(this) >= 0 (or the blueprint equivalent).

The trigger volume already keeps such a list: GetOverlappingActors.

1 Like

You may add a flipflop to toggle between states. Whenever an exec signal occurs, the flipflop change (and hold) state. In the following schematic, the system prints true or false to determine overlapping states

Hey. I was facing same problem and came out with something like this. You can add a delay between “Then 1” in Sequencer and Branch, so that loop leave some space for other actions. I don’t know how it will work in longrun, since I’m pretty new in UE4.

1 Like

PhysicsVolume and ActorEnteredVolume(class AActor* Other), ActorLeavingVolume(class AActor* Other) is what you were looking for.

Could use explain how to do this in Blueprint form?

This answer is completely useless! better luck next time guy

You can get voulme BSP information and check manually against the point, but it is possible only in C++ as I know.

bool AMyVolume::IsPositionInside(const FVector& Position) const
{
	bool bFallback = false;

#if WITH_EDITOR
	if (ABrush::NeedsRebuild())
	{
		// Fallback to the collision tests when there is no valid model
		UE_LOG(WaterMeshRuntime, Log, TEXT("Level BSP needs to rebuild."));
		bFallback = true;
	}
#endif

	if (Brush == nullptr) {
		// Fallback to the collision tests when there is no valid model
		bFallback = true;
	}

	if (bFallback) {
		UWorld* CurrentWorld = GetWorld();
		return CurrentWorld ? CurrentWorld->OverlapAnyTestByChannel(Position, FQuat::Identity, ECollisionChannel::ECC_OverlapAll_Deprecated, FCollisionShape::MakeSphere(0.01f)) : false;
	}

	// Use volume bsp here

	int32 nodeIx = 0;
	const FBspNode* node = Brush->Nodes.GetData();
	const FVector InnerPosition = GetTransform().InverseTransformPosition(Position);

	while (node != nullptr)
	{
		// Check if point is in front of plane
		if (node->Plane.PlaneDot(InnerPosition) > 0.0f)
		{
			// FRONT
			if (node->iFront != INDEX_NONE)
			{
				node = &Brush->Nodes[node->iFront];
			} else {
				return !node->ChildOutside(1, Brush->RootOutside);
			}
		} else {
			// BACK
			if (node->iBack != INDEX_NONE) // If there is a child, recurse into it.
			{
				node = &Brush->Nodes[node->iBack];
			} else {
				return !node->ChildOutside(0, Brush->RootOutside);
			}
		}
	}

	return !Brush->RootOutside;
}

works fine.

1 Like

This is not a useless method, it is the correct one. This can be used to check if something is still inside a trigger. The BeginOverlap only fires once when it happens, so it will happen once and set overlapped to true. Now if you ever want to check if the actor is within the volume you check if overlapped is true using whatever other methods you need whenever you need. All the time the actor is inside the trigger overlapped will be true. Only if the actor leaves the trigger it sets overlapped to false. All you need here is the check for the specific actor so not everything triggers it.

Setting up a bool upon beginning and ending an overlap is the correct, simple and recommended way to do it. Better luck next time kid.

However, this does not account for situations where the object is spawned within the trigger.

1 Like

I was having a similar problem because I was spawning characters within the trigger, and needed to know if anything was overlapping it or not.

I figured out a pretty simple solution to my problem at least:

  • Set up an Int value 0
  • OnActorBeginOverlap add 1 to it
  • OnActorEndOverlap subtract 1 from it

If the int == 0, you know there is nothing overlapping the trigger

This answer IS useless. Consider I have two objects. First object enters the volume so the ‘Overlapped’ variable sets to true. Then the second object enters the volume (the variable will remain true). Now if one of the objects leave the volume, the ‘Overlapped’ variable sets to false while I still have an object inside. This answer only works if you can guarantee that only one object can be inside the volume at a time.

By the way, As so many have answered this question I would like to add another way to achieve this. You also can use a ‘multi box trace for objects’ node and set the start and end at the center of the trigger volume (with slightly changed the end vector) and set the half size to fit the volume. it will output an array of all objects that you have set and also can ignore specific types of actors.

Regards,

yup I would do it like this as well. In this situation of something spawning in the volume do a check at spawn to manually set variables. In my situation I have players spawn inside a volume like so and I will tell the volume how many players have entered. You should also make sure that these variables are capped to never go past your max number of players and never go below 0.

This volume also triggers other spawning actors for zombies which I toggle active or inactive based on these variables. I use dungeon architect to procedurally spawn cities with also procedurally place zombie spawners. At level load I could do an initial sweep to check for spawners or I could do that way before while the player is loading in and keep track of all the assignments in a save file.

The reason this is difficult is because it’s blueprint. Blueprint is supposed to be like this because it forces to learn C++ which is for the most part better for everything. Don’t get mad, go learn :slight_smile:

This should do it. Basically it takes an actor (your pawn perhaps) and tests to see if the actor location is within the box bounds of a container like a triggerbox or a collision box or whatever you choose. This only tests for a single vector of the actors location within the container and does not test beyond that. If you need full collision testing, repeat the same code for the Actor that you see for the Container and test bounds within bounds or write a recursive function to test multiple vectors within the container bounds.

This assumes the input objects inherit from the Actor class.