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"

Tracing beneath HUD element / Crosshair

I'm trying to get a trace of all objects beneath a large, circular crosshair element on the HUD, but I don't know how to go about it. The goal is to have the player smart-target anything inside this large crosshair.

My first thought would be to do a shape-trace, but this wouldn't account for depth; the shape effectively gets smaller the further out it goes, and wouldn't be able to match the crosshair.

I also considered performing a series of line traces out from under the crosshair, but that would leave a lot of gaps for smaller objects to slip by.

I could combine ConvertWorldLocationtoScreenLocation with GetActorBounds to see if an object's bounding box overlaps the crosshair, but then I would need some way to reference each object on screen anyway. Since running that each frame on every object in the level would be beyond inefficient.

Is there some way to grab any object which falls within a certain space on the screen?

Product Version: UE 4.19
more ▼

asked Apr 14 '18 at 06:33 PM in Blueprint Scripting

avatar image

157 15 19 27

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Never used this node but it seems to be doing what you're after.

alt text

However, I don't think it's going to work for a circular shape as it's clearly designed to cater for RTS style rectangle selection. If you're versed in c++, consider taking it apart and see what makes it tick. Perhaps you can adopt it to your needs.

capture.png (27.9 kB)
more ▼

answered Apr 14 '18 at 07:25 PM

avatar image

15.3k 77 26 64

avatar image Grimwolf Apr 14 '18 at 07:28 PM

Thank you! Worst case scenario I can just change the crosshair bounds to a square/rectangle, but I think I can get a clear enough approximation by just run this 3 times over. Vertical rectangle, horizontal rectangle, and a square.

avatar image Grimwolf Apr 14 '18 at 08:01 PM

Nevermind. After some testing, this can't be run every frame. It's only meant to be run once as the HUD is drawn, apparently. Using it per-frame destroys performance and throws up constant error reports.

avatar image Everynone Apr 14 '18 at 08:07 PM

Shame. What is the error message if you do not mind me asking?

Did you run it off EventReceiveDrawHud?

avatar image Grimwolf Apr 14 '18 at 08:13 PM

"FirstPersonHUD_C_0 Canvas Draw functions may only be called during the handling of the DrawHUD event"

I have it running off Event Tick, just printing the names of actors found.

alt text

ue4huderrorbp.jpeg (82.5 kB)
avatar image Everynone Apr 14 '18 at 08:28 PM

I just tested it like this:

alt text

It has to be run in the HUD's unique event that fires every frame. It's quite performant.

Seems to be working fine this way.

capture.png (150.1 kB)
avatar image Grimwolf Apr 14 '18 at 08:39 PM

Cool, it does work. Just had to run it off the Event Receive Draw Hud event and it does exactly what I need.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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