Is there a way, to know if an actor is visible “on screen” ?
Thanks in advance
Is there a way, to know if an actor is visible “on screen” ?
Thanks in advance
yes there is. Kind of. Determining if any part of actor is on screen is not easy.
But checking if some location is on screen (or in camera fov) has node so its trivial.
You can check this way if origin of actor or some component is on screen.
Check out the 's plugin (the ultimate legend!) He has made a lovely little BP node (get rendered actors) to do just this.
Thanks @ULLS and @Nawrot, i’ve found another way, as my game is in 2D and the fact my question was in relation with the fact “my wish” was to be able to destroy an actor “fireball” when it’s out of the screen.
I’ve simply added around my camera a nice bouding box, and when my fireball “end overlap” the bounding box i destroy this actor taged as fireball !
Again thanks for your time guys !
Hello GolgothX01, I would really like you can tell me more details about your solution! since I am working on a 2D game too.
thanks in advanced.
I haven’t used 2d but I’d imagine this would still work…Just need to know which player controller to check so it knows what’s on their screen and then needs an actor to check their location…True, they’re on the screen…False they are not…I made a macro so I can use it easily but feel free to use as you please…
Just for the record, this function does not behave like that. People were asking for ways to determine if an actor is visible on screen. His function does not do this at all, it checks if the actor has been rendered which includes off screen rendering from what I can tell. This does not accomplish what the OP and others asked for, just saying. I mean its still a useful function its just not what people are led to believe.
I tap a swamp and chant.
"The Earth cannot hold that which magic commands."
This is the solution:
The viewport size returns the X and Y dimensions. if your world position exceeds those dimensions or lower than 0 (top left origin), then it is out of view.
Hook this up to a tick or timer.
I used pretty much the same way of checking if an actor is on screen in my project (ue4.26). However, I noticed one strange thing (or maybe I just don’t understand this fully). When I’m turned 180° from the actor (or wherever in the range of some -+60° from that point), the values returned stop changing, and it may give a false impression that the projected actor is actually on screen. So I started printing the boolean being returned: it was true when actor is on screen, and offscreen, but false only in that range where values returned stop changing (when the actor is offscreen, behind us). So, I added another pin to my AND operation and plugged the boolean returned from ProjectWorldToScreen. It produced the desired result and check seems to work every time.
Does anyone know why this happens though? I can’t really wrap my head around it, but I guess it’s hard (impossible) to project something to screen if it’s basically on the same parallel 2d plane or something like that…
The original solution was more aimed at 2D views.
In your case, what I would do is use the DOT product to see if the object is anywhere within viewing range of the character instead of using the screen.
Using the DOT product, you get a value of 1 (in front), 0 for the sides and -1 for behind.
As long as the value is above your field of view angle multiplied by that DOT product, your actor is on the screen for 3D view.
This is for first person btw.
For third person, this becomes even trickier due to depth. I am not sure how costly this would be but on a timer/tick you could do a trace between the camera front vector and the actor and check if they somehow align.
Hello! It’s my first time hearing of the “dot product” node. Could you please show me what the code would look like? Thanks!