x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.9
Tags:
more ▼

asked Nov 07 '15 at 12:57 AM in Blueprint Scripting

avatar image

HelloIAmMeat
31 4 8 11

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

Hello,

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:

alt text

more ▼

answered Nov 10 '15 at 05:09 PM

avatar image

Sean L ♦♦ STAFF
44.2k 485 149 436

avatar image HelloIAmMeat Nov 11 '15 at 09:52 PM

That worked perfectly thank you very much.

avatar image gagallo7 Feb 06 '17 at 09:39 PM

If you want to check if an actor is visible at the moment, there are two downsides with this approach:

  1. This blueprint checks only if the origin of the actor is within the screen, so it may not work with large actors, for example.

  2. The actor may be occluded by others and it is still on screen, but, if one of the occluding actors is opaque, the actor in question will be invisible at that moment.

To solve each one downside, you could:

  1. Treat the object as a box and check if at least one of the 8 vertices is within the screen, using the Sean's blueprint as base and GetActorBounds node.

  2. Use the node WasRecentlyRendered to check if the component was occluded or not.

avatar image Falconeyi Mar 04 '17 at 02:34 AM

could you show an example blueprint for problem 1? I'm not sure how to use GetActorBounds node here.

avatar image Hemlock Feb 06 '18 at 04:33 AM

how would i get the number of actors that are in the viewport?

(comments are locked)
10|2000 characters needed characters left

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.

Marc

more ▼

answered Nov 10 '15 at 03:06 PM

avatar image

mkamradt
294 15 136 34

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Nov 10 '15 at 04:21 PM

avatar image

alperenakyuz
2k 62 23 110

(comments are locked)
10|2000 characters needed characters left

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.

alt text

raycastfunction.png (220.8 kB)
more ▼

answered Dec 15 '18 at 03:45 PM

avatar image

Teknerd
1 1

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question