What's wrong with my code?

I am trying to create a cursor system that changes a sprite whenever the cursor goes to the left hand side of the screen, but nothing happens. My code is here, I’m fairly new to UE and Blueprints.

Hey there @OMNILUNAR! I believe changing the location to world space may be the issue here. So it will always give you back the world space values which change constantly depending on where your player/camera is so it would have little to no correlation with viewport size. Your math is right, just need to replace the Convert Mouse Location To World Space node. I’d recommend just using the raw Viewport Get Mouse Position like this:

Thank you for the answer! I’m a bit confused on the “viewport get mouse position”, how did you get this node? Is it your own function?

I replaced with a get mouse pos. Still not working.

Here, try using this BP exactly on it’s own, just hook up that event to event tick and it will print mouse positions and which side it’s on. Try it out and let me know, does it print correctly?

1 Like

This is what happens when i plug this into the event tick node. I replaced the “viewport get mouse position” with a “get mouse position” instead because i couldn’t find that node.


This is the BP

I have an adaptive camera system as well, and that could be affecting something

Interesting! It does seem to failing to get the mouse position at all when on the left side. I’m going to see if I can rewrite it with raw Getmousepos but do believe that the viewport variant is a native blueprint (at least in 5.0+), did you remove context sensitive when looking for the node?

I did remove context sensitive

There has been a new development. For testing, I added a sound cue to the event tick, and interestingly, it’s only playing the sound when my cursor is on the right side of the screen. That makes me think that there’s something wrong with the event tick itself or with something on the event tick line.

Alright, I fixed one part of the problem, it’s displaying the mouse positions on both sides now. I figured out that I didn’t attach anything to the “False” part of the branch node.

Great! Now does it properly detect values on the left side independent of resolution?

yes, It’s showing everything now.

Ahhhh I feel so stupid now. It was a problem with the animations. Thank you for the help though!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.