Moving mouse cursor with gamepad question - unity3d

So I can create a gameobject that I can move around like a cursor with my xbox controller, however when it comes to pressing buttons I have 1 issue.
It seems there is no way to set the actual mouse cursor position without importing user32.dll and even that solution will only be a windows solution. https://answers.unity.com/questions/330661/setting-the-mouse-position-to-specific-coordinates.html
The reason I want to move the actual mouse cursor as well as my gameobject representing a cursor, is that I still want to be able to click buttons, and when I call Input.GetMouseButtonDown(0); it will click the button at the point where the actual mouse cursor is, and if the actual mouse cursor isnt moving with us its not gonna work.
Also I dont need a custom mouse cursor, if the xbox controller could move the mouse cursor directly thats fine too.
Any advice appreciated.

There is no other way to set the mouse position maybe if you needed to have a solution for mac as well you can find it here at the bottom.
also making a custom cursor is a better solution cause it will be cross platform and you could make a custom mouse down event for it so i don't see why you wouldn't
and if you are sure you need the actual mouse to move you only have the first solution
and moving the mouse with xbox controller by using a software is only gonna work on your pc and those softwares are probably using the first solution

Related

Interaction with object by pressing E button using ue4 blueprints

I am a begginer in ue4 blueprints system. I've wanted to create simple code: player enter the trigger box, and press E, after that text should appear on the screen. What I did wrong in my code?
I'm no expert, but I think you should use a branch node to check if the key is pressed. No harm in also changing your other character to a getplacyercharater.
Best of luck :)
On Component Begin Overlap (Box) fires on the frame you begin overlapping. Unless you pressed E on the same frame you begin overlapping, this will not work.
For this to work, you would have had to be checking if it was overlapping and for the key press on every tick. Don't do that, it's a waste of time.
What you could do instead is On Component Begin Overlap, set a variable to record that you're ready to interact, and then check for that variable when you press E.
This is something I did recently using the Top Down template that demonstrates 'move within distance of object, press button, thing happen'
Adding an object to a 'ready to interact' array on overlap in Player Character.
Detecting a mouse click, checking if it was in the array, doing stuff in Player Controller.
It sounds like you're building an interaction system though, so if you want this to be as re-usable as possible you should probably have this code on your Player Character / Player Controller, and not in the object you're interacting with.

Drop In Drop Out System with Input?

I'm trying to code a drop in drop out system with input. Basically i have 2 sprites and im trying to swap between controlling each one. Right now I have a button i press and it switches which sprite is active however it does not let me show the animations for the other sprite and i can't control it. It also makes the other sprite that i'm not swapped to go off screen. I need both sprites to stay on screen and be able to press a button and and be able to control the other with the same input. If anyone could help me it would be much appreciated i couldn't find anything about it on google considering this is a very specific problem.

Scene screen is stuck

I'm new to Unity and I'm trying to make my own game (or at least learn to). I have a problem in the scene screen.
The scene screen is stuck on this mode and I don't know how to bring it back to the original camera view(hope you guys understand what I'm meaning), Tried to search how to do it but couldn't specified what I want, please help.
The Canvas when in Overlay mode turns out to be a giant object compared with normal scale.
You are just too far from your objects, to return to normal you can navigate manually right clicking Scene window and moving with WASD and QE.
Another workaround is that you use the FIND shortcut like following:
Click the object you want to find on Hierarchy window
Move your cursor to Scene window without clicking
Press F on your keyboard
If perforned correctly the Scene camera will find that object and you will be right back to where you were.

UE4 Enabling Mouse During Play?

I'm extremely new to UE, and doing a few easy tutorials to get started, so I don't exactly know the correct terminology to use to help me find what I am looking for... Anyway, whenever I hit play and the game starts, my mouse disappears and I am only able to use the input that I set up; so my question is, even though I do not need mouse input for movement, as I am using WASD, how do I keep my mouse unlocked and available to move around without being locked to the camera?
When you hit play and the game starts, your mouse gets captured by the game to control the camera. If your play button is set to play in the viewport, you can release the mouse from the viewport by pressing Shift-F1. The game will still be running, but input (including from the keyboard) will be suspended and you can interact with the editor.
You can also change the default behavior of how the mouse is captured and it if is constrained to the viewport boundaries. To see these options, go into the project settings (settings button above main viewport/project settings...). On the left side of the project settings window, select 'Input' under the Engine heading. On the right side will be some mouse preferences that can change its behavior.
For instance, to allow the mouse to travel outside the viewport, change 'Default Viewport Mouse Lock Mode' to 'Do Not Lock'. I don't recommend this, but you might experiment with these to get a feel for what they do. Also, you might look up these settings in the Unreal documentation for more detail.
There are 3 blueprint nodes that change the input method:
Set Input Mode Game
Set Input Mode Game and UI
Set Input Mode UI
You want a combination of the second one and a "Show Mouse Cursor" node. However, if you are making an FPS and you use the mouse to look around, you may lose that ability with the second node above. It comes down to what your game is and how you want to use the mouse.
I had the similar issue. So I did something like this in Level Blueprints to achieve what I want.

Allowing click or raycast to only certain items at time

This is kind of hard to explain so I try to do my best using the following image.
So the case is this: player has selected drill from inventory and "Confirmation menu" (A, S & D) has popped up. Now the player must select one of these actions (A = accept position, S = put item back to inventory, D = keep moving object around). Before the player chooses from one of these action he should not be able to do NOTHING else.
The problem is that if the player clicks the minimap in the upper right corner a button click is detected and menu is opened. If the player clicks the car (detected with Raycast) player gets inside. If the player drags the joysticks he starts walking around (using Unity's Joystick script). NONE of these should be allowed.
To the question: does Unity have some kind of method to "Prevent any kind of click detection to any other objects but these" OR "If mouse is not over this object do nothing when clicked"? There probably is nothing like that so what would be the best workaround?
Because these "click to do something" actions are triggered from various places with various styles (buttons and raycasts in tens of different scripts) I try to avoid doing this by setting booleans everywhere. Open ideas are more than welcome.
An easy workaround could be via using GUI Depth (https://docs.unity3d.com/ScriptReference/GUI-depth.html).
If "Confirmation menu" guiDepth is on top and all the other GUIs are below, you could add another GUI in between covering the whole screen; a Raycast would then return the first element and if it's the middle GUI just do nothing.