Best way to chek is any part of actor visible

Is there any good solution how to chek is any part of actor visible?

For example:

Enemy is partly behind the wall. And if i simply trace for it, trace will be blocked by wall, but player can see part of enemy.

Is there a better way than just tracing every part of the enemy?

Thanks for any help. And sorry for my English)

Interesting question! I would like to know that too :smiley:

Vote for this. It will attract more people. Or not :slight_smile:

I would like to know too !

I don’t know if you can extrapolate something from this to help with your problem.

You could do a line trace for every degree between 0° and 180°, so you basicially check the whole region in front of you. If none of those traces finds the char, you know that he isn’t there… Obviously, that’s not the best solution, but it would work…

I thought about it. But I don’t understand how to get scene texture, and how to work with it in event graph. And if it possible, it’s still based on render. But i need to check actors that not on screen.

I hope there is more elegant solution exist.

After a lot of time I somehow got to think about this question again, you can easily do this with a SPHERE trace for MULTI objects with the channel visibility. And then casting the results to your Class until you have hit that class or are out of results.

C++ variant:

			TArray<FHitResult> OutHit;
			InActor->GetWorld()->SweepMultiByChannel(OutHit, Start, End, FQuat(), ECC_Visibility, FCollisionShape::MakeSphere(50 /*Character height*/), FCollisionQueryParams::DefaultQueryParam, FCollisionResponseParams::DefaultResponseParam);
			for (int i = 0; i < OutHit.Num(), i++)
			{
				AActor* /*Actor class*/ Tester = Cast<AActor /*Actor class*/>(OutHit[i].Actor);
				if (Tester)
				{
					return Tester;
				}
			}

//Written in 5 mins, not tested but should work, may need to check the returning :wink:

I know it is late, but I thought I would write it anyway;

I would like to know too !

If occlusion culling is enabled (which is highly recommended for performance), you could use the WasRecentlyRendered function.

I don’t mean to derail this discussion… and I know the following sounds utterly mad and I haven’t tried it… but it just might work and be very efficient… is it possible to add pawn sensing or AI perception to the player controller?

Replying since this is one of the top results on Google. Is there an elegant solution to this one yet?

If I’m understanding the proposed SweepMultiByChannel solution, I believe that will have the opposite effect, where the trace will be blocked before getting to the actor in all scenarios except where the target is completely visible to the sweep. In other words, if 90% of the target is exposed, the trace will still be blocked by the wall covering the other 10%.

The only way I can think to solve this (with my limited knowledge) is to perform multiple traces around the edges of the target, and consider the target “visible” if at least one hits.

1 Like

This seems like there should be an easy solution, but in my Beat Em Up template, the only thing I found I could do was create a box collision about the size of the playable / viewable screen to know if things are there or not within that box.