Set input mode game and UI and control character camera

Hi,

I’m trying to modify Dialogue Plugin so that my character can enter “conversation mode” and keeps freedom of movement.

Right now my setup is very simple when I enter conversation I’am able to choose my answer using mouse wheel and conforming it by pressing left mouse button. Because I’m using “set input mode game and ui” my character is able to move freely but I can’t look around.

Is it possible set input mode game and UI and still control my character camera? Or maybe there is another work around for this problem.

Hello LordZedd_02,

You could capture your mouse cursor when you’re using the game and ui input mode.
Alternatively you could use the game input mode and forward the scroll event to the widget, which would be the solution I’d personally use and recommend, if you only the mouse wheel input and the player isn’t supposed to click on those options.

Hope that helps. Just let me know if you’re in need of further assistance.

Regards,

Vecherka.

Hello,

Thank you for such a fast answer.

What do you mean by capture mouse cursor and how can I forward scroll event to the widget?
If I understand you correctly in second option I would be able only to scroll through my answers without ability to click on them using left mouse button is that correct?

Thanks in advance.

Yes that’s correct, what you said about the second option.

The following setup uses the game input mode and these three events to control an active widget. By default you cannot control widgets while the input mode is set to game only without additional setup.
Inside the widget blueprint I created three custom events:

296696-inside-the-widget-blueprint.png

These are the target events I want to call with my input events, which are handled like this inside the player blueprint:

296697-inside-the-player-blueprint.png

Bear in mind though you have to make sure you actually can forward them, as in the widget exists and you’re currently in a dialog. And if you’re not currently in a dialog you don’t forward that input at all, a simple branch statement should do the trick (which I forgot in this example).

As with what I meant by capturing the player cursor, by default if you use the game and ui input mode the mouse x, and mouse y events get consumed before they reach the player in the input stack, except if the cursor gets captured, in which case the input gets received by the player (by default you can hold the left mouse button down, while in game and ui input mode, and you can look around again).

Thanks for such a detailed answer but that part is ready. Inside my widget everything is handled by “on mouse wheel” function similar to what you just suggested.

Last think that I need to figure out is how can I move my character camera freely when I enter conversation. Right now using “set input game and UI” I’am able to do that only when I hold my right mouse button.

The game and ui input mode prioritizes the input to the ui before the player, so in order to keep the controllability of the player character, I’d use the game input mode, and forward the necessary inputs to the widget, which I is what I’ve done here. I used the game input mode and forwarded these three controls to the widget reference, in order to control the widget, while holding the controllability over the player character.
My apologies, I should’ve given a better explanation before hand.

Ok, so did what you suggested and unfortunately its not working but my guess its because I did something wrong. So this is how it works inside my project.

From my character blueprint im shooting line trace if it hits my NPC it is sending the message to my NPC to create widget blueprint. After adding it to viewport I’v change input mode from “game and ui” to “mode game only”. Ad this point everything works just fine widget appear in the game and I have full control over my character.

I’ve created custom event inside my widget blueprint and I’m calling it inside my character blueprint. This is probably the part where I mada a mistake. I’ve created and hook up new variable (variable type is my blueprint that im trying to call) to the custom event. So far so good and this is working but only inside my character blueprint. My event inside widget do not receive anything and I’m getting error “Accessed none trying to read proper widget”

Where do you create the widget, inside the player or the npc? The error you’re receiving means that your variable is not set or the reference is invalid.
If you create it inside the npc, make sure to give the reference of the created widget to the player, and use that reference to target the events. You could use either a callback, to give said reference to the created widget back to the player, if the message is an event on the npc, or the return node if is a function.

My widget is created inside npc and I don’t know how to reference created widget to the player. How to use a callback? Here is a screenshot of my setup hopefully that will help.

I just mimicked your blueprint setup, so you can find the changes easier. But I’m going to list them out, just in case:

  • I added a variable in the npc blueprint called ‘DialogWidget’, and set it after it has been created.
  • I also added an integer input variable to the interface function ‘Interact’ so multiplayer can be achieved easier. It is not necessary in your setup, if you don’t plan to implement multiplayer, but if you do you’d have to add the blueprint to the player screen and not the viewport.
  • After it has been successfully created and added to the screen, I then send it’s reference to the player, via a custom event inside the player blueprint. You should cast to your correct player blueprint class, I assume you did the player logic inside your player pawn or player character blueprint.
    If you’re instead using your player controller you just have to cast the player controller to your correct class.
  • One more thing, you don’t have to call the ‘set input mode to game’ function if you haven’t changed it somewhere else, by default the engine input mode is the game input mode.

Here’s my mock up of those changes, inside the npc blueprint:

And here is the custom event inside the player blueprint:

296730-added-custom-event-in-player-blueprint.png

Great that worked! I had to change one thing (cast to actor component not character blueprint). But jeah it is working.

Unfortunately now my system for highlighting the answers in dialog do not work. It was handled by “on mouse wheel” function but well you get something and lose something.

If you can handle more of my stupid question I would like to ask how can I fix this?

None the less thank you for your help and time.

Glad to hear, and sure I can help, I only helped you half the way.
Now that you have the reference to the widget, you can replace every occurrence of the ‘Mouse Wheel Up’ event inside the widget blueprint with your custom event ‘IndexUP’, and it work just fine, same with the ‘Mouse Wheel Down’ event. In the player blueprint you then can forward the respective events to the correct one in the widget.

Just one more thing, try not to use the ‘Get All Actors of Class’ node, this node can gets more expensive with the number of actors in your map. If your player character is of class ‘Horror Engine’ you can cast your controlled pawn to it. If this is instead an actor component, you can get the controlled pawn, and get the component via the ‘Get Component by Class’ node, and continue with that.

I’m attaching my blueprints it will be easier that way.

Yes I did what you suggested, inside my widget blueprint I’ve created custom events. And they are responding to my input but like I said before I’m no longer able to change the answer using mouse wheel.

My guess is because there is no number attached to mouse wheel before new setup I could identify if mouse wheel was going up or down by number 1 or -1.
May be you could analyze the code for that I tell me how can I fix it.

Fortunately left mouse button is working and I am able to confirm my answer but I get an error “Accessed none trying to read property widget” which is weird because everything works fine.

And last thing I dont know how to replace “Get All Actors of Class” this is the only solution that I was able to come op with. I cant connect anything else to object in “cast to horror engine”.

296794-bp-npc.png

Have you checked if the function gets called (i.e. via a ‘print string’ node)?
It would be great If you could provide an screenshot from the error message, or the complete message as a simple text, because I don’t know where the error’s happening.
Is the Player an Horror Engine child class, and or a pawn child class (I don’t know how the ‘Horror Engine’ kit is set up)?

Yes, and its forking perfectly fine despite en error.

Here is the screen

shots with all the info.

This is how you should be able to replace the ‘get all actors by class’ node. You get the player controlled pawn (which should be of type ‘HorrorEngineCharacter’). You cast to said type, and the get the child actor component, which is just an other variable.

To make sure your widget actually exists, you can check if the reference is valid, this should be used inside the confirm event functions as well as the mouse wheel function, inside the player blueprint. Just connect everything with the exec pin.

296809-is-widget-valid.png

I guess you called the old ‘On Mouse Wheel’ function from the ‘On Mouse Wheel’ event inside the widget blueprint, and you made sure the function gets called?

There are good news and bad news. Good one is that “is valid” fixed the error. Bad one is that I still cant get rid off ‘Get All Actors of Class’ (screenshot)

For the mouse wheel I couldn’t called existing “On mouse wheel” function. I got information “this function was not marked as blueprint callable…”. So what I did instead I’ve copied nesesery code and created new function that I can access. This technique worked with “on key down/up” function. And jeah I’ve made sure that function gets called.

I think that function receive the input but simply don’t know what to do with it. Technically nothing has change accept the fact I don’t need to specify if my mouse delta is 1 or -1.

Just in case I’m sending once again mouse wheel function.

As for your ‘get all actors by class’ problem, this should do the trick:

My apologies for not going that far beforehand.

If you confirm your selection does it use the correct option, and just doesn’t highlight the option that is currently selected? I don’t know how this is set up so I can only make uneducated guesses, it seems to me like it should work though.
You could try to call the old function and check if that still works.

Awesome, at last casting is working.

Yes it use correct option and highlights first selection but I cant change it.

I tried the old function and its working just fine.