# Locking mouse in center of screen

**URL:** <https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [May 28, 2024, 7:44pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606 "2024-05-28T19:44:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Voltron1017](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Voltron1017](https://forums.unrealengine.com/u/Voltron1017)\
**Post date:** [May 28, 2024, 7:44pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/1 "2024-05-28T19:44:13Z")

</div>

How can I force the mouse to stay in the middle of the screen in first person? I need to do this WITHOUT event ticks.

---

<div class="post-metadata">

**Author:** ![Nawrot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nawrot/32/618260_2.png) [@Nawrot](https://forums.unrealengine.com/u/Nawrot)\
**Post date:** [May 28, 2024, 8:13pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/2 "2024-05-28T20:13:42Z")

</div>

Just hide mouse cursor, put same cursor in middle of screen. Do logic that reads mouse cursor location when mouse is free, and reads middle of screen when mouse is in center.

However this is quite strange behavior you want, can you explain what is reason for it?

---

<div class="post-metadata">

**Author:** ![matrem84](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@matrem84](https://forums.unrealengine.com/u/matrem84)\
**Post date:** [May 28, 2024, 8:32pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/3 "2024-05-28T20:32:59Z")

</div>

I add the same sort of need, when using first person with mouse used to click the UI, and right mouse drag to look around. So I needed to hide the mouse on right drag + center it to avoid being blocked at screen border.  
But I was doing it in blueprint, and it was not so easy to do it correctly.  
Often games do it otherwise, press a key (alt for example) to show mouse and click the UI, and otherwise get the normal fps behavior, certainly easier to do in unreal.

---

<div class="post-metadata">

**Author:** ![Voltron1017](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Voltron1017](https://forums.unrealengine.com/u/Voltron1017)\
**Post date:** [May 28, 2024, 8:54pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/4 "2024-05-28T20:54:18Z")

</div>

I have a drying rack in a survival game I’m making and the player can hover over food and eat it/take it. The logic works by using the “Begin Cursor Overlap” event on the piece of meat and then showing the player the widget. Setting the position every frame using event tick caused it to glitch out. ALSO, I’d like to refrain from raycasts/line traces.

 ![q2eowjiaoididowsjidj](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/b/fdb2362eef939549ecca3bdb4190bb598e4f68ed.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 28, 2024, 10:07pm UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/5 "2024-05-28T22:07:21Z")

</div>

> [@Voltron1017](#):
>
> ALSO, I’d like to refrain from raycasts/line traces.

But why?!

> The logic works by using the “Begin Cursor Overlap"

This is already performing a trace you’re trying to avoid, but worse.

---

<div class="post-metadata">

**Author:** ![Voltron1017](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Voltron1017](https://forums.unrealengine.com/u/Voltron1017)\
**Post date:** [May 29, 2024, 5:27am UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/6 "2024-05-29T05:27:46Z")

</div>

Now that I think of it it would probably be the best option, but, how can I check if the raycast hits air? So the prompt disappears when the player isn’t hovering over the meat.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 29, 2024, 5:31am UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/7 "2024-05-29T05:31:09Z")

</div>

Line trace returns a bunch of data, it will tell you when you’ve hit nothing - no blocking hit, or no component, or no actor. Here’s the entire setup which also accounts for proximity:

> [@Third person crosshair object highlight troubles](https://forums.unrealengine.com/t/third-person-crosshair-object-highlight-troubles/252041/13):
>
> The communication in the example revolves around Inheritance + Interface - a potent combo, imho. the base class implements the interface (which children inherit) the widget uses the same interface - calls children receive can be propagated: Actor → Widget Component → Widget without casting or finding user widgets (this can be done in many ways, though) the player has a collision sphere and sends an interface call to overlapped actors as we approach: [image] [image] Above, handl…

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [June 28, 2024, 5:32am UTC](https://forums.unrealengine.com/t/locking-mouse-in-center-of-screen/1877606/8 "2024-06-28T05:32:05Z")

</div>

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