How to determine if an actor is on screen?
What is a good method of determining if an actor is located on screen? Essentially when the player presses a button the game stops and they can select an enemy from an array to perform an action on. I'd like to remove any enemy that is not currently on screen from that array, or not put an off screen enemy in that array in the first place.
asked Nov 07 '15 at 12:57 AM in Blueprint Scripting
You can try to use this setup, which will check to see if the object in question is in view. If you're trying to check for multiple objects, you can replace TestCube with a foreach loop that will run through each of the objects you'd like to check.
Here is the setup:
answered Nov 10 '15 at 05:09 PM
Sean L ♦♦ STAFF
Every scene component holds an "Is Visible" bool that is updated during rendering. You could iterate over all your enemy actors and all their scene components to sort out those being visible. However this is probably a slow operation. Maybe you could try to improve performance by first using BoxOverlapComponents with a "bigger than screen" box to sort out those that are really far away and just iterate over the rest.
answered Nov 10 '15 at 03:06 PM
UMG widgets have functiona that can twll you if a certain point in the world is on the screen. You can use your actors locations and get that information. You can even check for more than one point on the same actor (the body maybe offscreen but the hands or weapons are on screen) by getting mesh socket (or bone) locations.
answered Nov 10 '15 at 04:21 PM
This thread is a bit old and maybe some of my implementation wasn't available at the time. Also, I should specify this is really only good for detecting one actor not multiples, but in my case that was exactly what I needed. I think this is a fairly efficient method and it is working beautifully for me. I am using a ray cast at a starting point away from my main pawn and then casting to a specific distance out to see if it hits an actor. Please excuse some of the blueprint look I had to squeeze it down to be able to fit in one image. I did all of this as a prelude to getting the highlighting of actors working, the first obvious step being to detect the actor in the view port. Please note this is currently rendering the ray cast line, you can eliminate this by setting the draw debug type to 'None'.
Basically how it works is you call this as a function (I am doing it after a movement of the player controller) and it will get the currently controlled pawn, find the forward vector and cast a ray straight forward for a specified distance. The two multipliers after the 'Get Forward Vector' call is what controls these parameters. I could hook these values out to the function parameters in order to control the ray cast distance but I didn't do it for testing. You have to have the collisions set up properly for your actors. In this case I used WorldDynamic to filter, so for this setup it wont register a static mesh like walls or doors, it will only detect actual actors. For this case, my actor collision preset was set to OverlapAllDynamic.
The last part of it is to store if an actor was hit and which one was hit. I then call a custom event after this function call to trigger another piece of code in the controller to process the hit.
Follow this question
Once you sign in you will be able to subscribe for any updates here