How to prevent triggering behavior if the hit actor is off screen?

I have floating damage numbers that I want to skip spawning if the hit actor is off screen. I of course still want the damage to apply which it does, but how do I detect if an actor is on screen? I’ve tried Project World to Screen and it always returns true. I’ve also tried WasActorRenderedRecently, which again always returns true. I’ve also tried WasComponentRenderedRecently, which always returns false. Is there no way to easily and efficiently do this? I’m also going to need this to reduce tick rate when something is offscreen so being able to check for this is pretty vital.

“WasActorRenderedRecently” should work. Perhaps your character has a collision sphere greater than its volume (like an attack range) that is throwing off the functions.

If so try turning the parts that extend past your characters collision trace channel where it says “visibility” to ignore and see if this changes the way WasActorRenderedRecently triggers

Try posting the information to screen on tick about the visibility (just set a key for the text so it doesn’t spam the screen) and see if it changes.

2 Likes

Nope, just an Actor standing off screen for the purpose of testing. Has a small capsule collider.

Not sure what you mean by this. The mesh itself has collision entirely off. The only collision turned on is the capsule collider on it.

I’ve already done that and “WasActorRenderedRecently” always returns true. Found some other topics complaining of same issue so I think I need to find a different solution. I guess try getting viewport position of the actor and comparing that to viewport size to see if they’re out of the viewport, but I wonder what the performance impact of doing that would be.

You could try this camera test. Seems like a lot of blueprint work though.

That’s a bit beyond what I need as I don’t need to test for the camera actually seeing it. I really am just needing a rendered test so I can skip certain behavior for something not rendered (as well as adjust their tick rate if not rendered). “WasActorRenderedRecently” SHOULD be the solution, but for some reason it’s just buggy and always returns true. Only thing I can think of is SOMETHING is causing it to render, but I have no idea what as there’s only 1 camera in my map.

Edit: Oh! They have floating healthbars as widget components. Wonder if that’s what’s causing it. Even though they’re off screen maybe the widget is still causing the actor to render. Will experiment further with an empty cube actor.

Added a simple cube actor. Has nothing on it. In its tick it’s checking “WasActorRenderedRecently” and the result is it always returns true. There has got to be some sort of wonky bug going on here.

Aha, it’s my directional light. Soon as I remove the directional light actor the function works fine. Now to figure out why it’s doing this.

Now for the reason the direction light is doing this: Dynamic Shadows

Turning dynamic shadows off solves it, but why would an actor be casting shadows when it’s offscreen to begin with? Anyone have any suggestions?

If the actor is off screen and casting a long shadow, then the shadow could fall within the camera frustum. If this wasn’t taken into account then you would have constantly shadows flickering in and out of existence at the edge of your screen.

The actor is 3 screens away. The shadow its casting is not long. Below is the cube with its shadow.

image

Are you testing “Was Actor Recently Rendered” on tick? For test purposes for now
edit :(not visibility)

Yes.

All that cube is is an actor with a cube component with that tick event on it. It has nothing else and does nothing else. The only solution so far is to turn off dynamic shadows on either the cube or the directional light, but then I of course lose dynamic shadows.

Is your camera set to perspective or orthographic? Seems the cube has no perspective distortion.

Orthographic probably doesn’t have a classic camera frustum to use for tests. (after some tests it definitely catches the object out of the viewing range, though it’s not 3 screens away)

It’s set to perspective, but there seams to be 2 cameras in my map. The one attached to my actor and another spawned in by the engine.

image

CameraActor is not something I’ve put into the map. When looking at it it can’t seam to see anything, but maybe it’s triggering the rendering? Deleting it doesn’t seam to solve the issue though.

Do you have a mini map by any change? Those are usually render to texture cameras that have a wide range.

If there is an extra camera then delete it, it might trigger the visibility unless it’s inactive.

Do any of the other characters beside the player character have cameras in their bp’s?

I do not.

The camera doesn’t exist in my map. It’s spawned in by the PlayerCameraManager for whatever reason.

Nope.

The cameraActor is probably spawned somewhere in your blueprints. It’s not a default engine action on play if you have a camera in your main character.

Try looking for it with the reference search inside of your blueprint (there is a grey icon with a binocular symbol to search through your whole project)
Try finding CameraActor

CameraActor is managed by UnrealEngine. It’s always spawned. Besides deleting it doesn’t solve anything. “WasActorRenderedRecently” still returns true even if deleted. The only thing that changes this is turning dynamic shadows off.


It’s not a normal situation for CameraActor to be spawned. It has nothing to do with the camera manager.

I’ve worked in this engine for years and I’ve never seen that behavior by itself.

Create a new TopDown sample project. Press play. You’ll see double camera. 1 is attached to the player and the other is CameraActor. This isn’t me doing this. The engine is.