UI Hit Box Location Incorrect?

I have just begun setting up a turn based rpg game, and I just started making a menu. I went to the Content Examples HUD map to get the draw button function, migrated it into my project, copied the function over to my HUD blueprint, and have made some changes to it to make it easily scalable. However I have run into what seems to be an error where the hit box is not in the same position as the texture (even though both have the exact same co-ordinates plugged into them.) I have tried multiplying the Y position of the hit box by numbers (the X position is always correct, it’s just the Y co-ordinate which is wrong) but it seems like the amount it is offset by is exponential, so multiplying it by any number only works for one co-ordinate and no others.

Does anyone have any idea for what is going on here?

Thanks :slight_smile:

[EDIT]
I tried copying over the exact function from the blueprints example HUD and the same problem occurs.

[EDIT 2]
I also tried setting the location in pixels and not in viewport size / a number and it continued with the problem.
Does the viewport size return the size of the playing view or the whole screen size?

[EDIT 3]
Did some tests and the viewport/screen size is the actual game screen size so that’s not the problem :confused:

Hey, WarLord!

Have you tried sneaking some ‘Print’ nodes before your AddHitBox and DrawTextureSample nodes? You could have them print out the X and Y values just to make totally sure they’re correct.

It looks like your ‘Draw Texture’ X and Ys are based off of (Location) - (One half of ( Scale * Location ) ), while your ‘HitBox’ X and Ys are based off of (Scale * Location). I might be a little mixed up, but it seems like those two locations would definitely end up different. Let me know if I’m misunderstanding, hopefully we can figure this out.

Hi Jonathan, thanks for the reply.

But no, it’s a bit hard to tell, but the position for the hit box is plugged into the same vector 2 that the texture uses, however for the texture position I need to break the vector apart :slight_smile:

And I have tried the string thing and the texture and text are in the right position.

Thanks :slight_smile:

Any answers?

I can’t reproduce your issue on my end.

As a last resort, you could upload your project somewhere and send me the URL in a private message. That would make it much easier to find a reproduction of the issue.

Here is the link to the HUD.uasset I am using (you wont need any of my other assets) :slight_smile:

Same problem. Hitboxes don’t register and when they do they register in the wrong place.

You could try calculating the position step by step.
Use Location that you 100% know where they are, like half of the screen size (both coordinates / 2).

You can see your hitbox with “showdebug hitbox”. Type this in the console (maybe you need to remap the key for it).

If the upper left corner of the Hitbox is in the right place, than add the next numbers to it until you find the source of the misscalculation. You can also plug in the same location into your Texture to be sure that both are in the same place.

Thankyou, but I have tried that and it doesn’t work. :frowning:
However this problem is essentially obsolete now that we have UMG.

I have discovered the first part of the problem. When you constrain the aspect ratio of the camera, the debug area of the hitbox doesn’t move with the hud but the draw lines do. So it looks like you are entering and leaving the hitbox with a weird offset.

Hey, WarLord.

We haven’t heard from you in a while, so I’m marking this question as resolved for tracking purposes.

Regards,

Jonathan

I have the same problem. However, I found that it must be caused by something else.

In my inventory HUD, all the elements are positioned by percentages to fit all (wide) screen sizes. In 1080, the hitboxes seem to register with the whole hitbox offset by N pixels (to the left, in my case). The “showdebug hitbox” shows the hitboxes in the correct location.

However, in 720 mode, the boxes were located correctly like before, but the boxes also registered at the correct place as well.

Yea there is something going on w that console command “show debug hitboxes”. I don’t think it compensates for aspect ratio of the screen so they always are offset.