Unreal Engine Blueprint – Disable Every Key Except One

Tutorial / 13 November 2023

Unreal Engine Blueprint – Disable Every Key Except One

Below is the easiest way I know to leave only one key active and this overview will show you how to set this up in your specific blueprint(s).

In my case I used this when I had disabled the player character during the playing of a video, but I had no way for the player to exit the video before it got to the end. So, I added the functionality below to only allow for the use the E key to stop the video.

IN THE BLUEPRINT ACTOR:

  1. For this approach to work I used the Disable Input node.
  2. For example, create a Blueprint Actor with a collision box that triggers when the player enters the box.
  3. Then use the Disable Input node to disable the player character. Then add to this node: Get Player Character and Get Player Controller.
  4. Please see image below for how this is done and for now ignore the other nodes outside the red lined area – we will come to those shortly.

IN THE PLAYER CONTROLLER:

  1. Create (if required) or Open the Player Controller Blueprint.
  2. Add in the code below.
  3. As it’s the Player Controller BP there is no need to add in any interfaces, enable or disable inputs as it automatically recognises key mappings.
  4. Add a Branch:
    1. Create a Boolean variable (you can promote the Boolean that is part of the branch node or just create a new bool).
    2. Call it Enable E Key (for example, but this could be any key you require).
  5. Add any additional nodes required for your actions:
    1. Below I’ve added a Remove widget node, but your code will (or may) require something different or nothing additional.
  6. Add an: Enable Input (this will enable input back in the player character).
    1. At the end of the node chain – Set the Boolean back to false/off.
    2. See Player Controller final graph set up below:

BACK IN THE BLUEPRINT:

  1. Create a Custom event.
  2. Call it Enable E key (or whatever you require).
  3. Cast to the Player controller and plug get player controller into this node.
  4. Drag off the cast node, search for and select the Boolean (created above) and switch the Boolean to on/true.
  5. Now add the Custom event after the Trigger key/action – so the custom event casts to the player controller and switches the Boolean on.
  6. This is done so that the enable input connection to the E key only becomes active when entering the specific blueprint (created above).
  7. See final graph below:

FURTHER INFO ON HOW THIS WORKS:

Boolean Switch: Please note – you don’t need this Boolean and Branch, but I’ve added because if it’s not there the E key and activating Enable Input will be active all the time and will use unnecessary compute power and may conflict with other controls and E key actions.

SUMMARY of HOW THIS WORKS:

In the initial blueprint – the target is what is getting disabled and not the Player Controller. The player controller is basically being used to say do not allow input against the target – which is this case is the player character.

Please also note: You do not have to have the player controller node plugged in. It will still work without it, but does provide more granular control over what is being disabled. The player controller is what acts as the interface between the player and the pawn, so also consider if the player is using a gamepad and how does the E key or interact key relate to the gamepad in this case – as you may require some additional coding.

Technically using this approach, you are disabling the player character (so this includes all the player inputs/keys), but for all intent and purposes you get the same result.

Below is a simple diagram showing the process flow for how this works:

Appendum

If you are using this specific set up for removing and stopping the play of a video. You can also add the additional nodes at the end (Player Controller) to remove the sound/stop video playing. Otherwise, you will still get audio playing even after removing the widget. (Make sure the in the Media Player variable node details – you select the required Media Player).

I didn’t add this above as it’s specific to a widget playing blueprint and the above is meant more as an overview for one simple way to disable all keys except one.

Related Video Blueprint Tutorials

This tutorial can be used in many different scenarios, but will be useful if you disable input while a player watches a video. Please see below related posts regarding video tutorials.

  1. How to upload and play video.

  2. How to Play video in a widget.

  3. How to Automatically Remove Video when it finishes playing.

  4. How to Disable Every Key Except One.

For further tutorials on blueprints please see the page here: Blueprint Tutorials or to get started with blueprints please see here: Get Started with Blueprint

If you have any questions, please leave a comment or drop me a message directly.

The post Unreal Engine Blueprint – Disable Every Key Except One appeared first on Motion Forge Pictures.

Report

Unreal Engine – Play a Video in a Widget

Tutorial / 13 November 2023

Unreal Engine – Play a Video in a Widget

VIDEO IMPORT AND MEDIA PLAYER:

  1. In the Content Folder create a new folder called Movies
    1. If the video is not in this folder, it won’t get packaged in the game.
  2. Drag in a supported video file into the Movie folder.
  3. This should be in a compressed video format such as an mp4.
    1. See the link here for supported video formats: Supported Video File Formats
  4. Also move the video file into the Windows/PC project Movie folder using the PC folder browser (I.E: Move the video again into the PC folder).
  5. Right click in the new folder and in the menu find (Media > Media Player) and create a Media Player.

  1. A panel will pop up and be sure to tick the box to create a media texture asset.

  1. Back in the folder > Right click on the media texture and from the pop-up menu create a material.
  2. Open the Media player. Double click the video file to make sure it plays.
  3. Tick the loop box if you want it to loop.

WIDGET:

  1. In the same folder (or if you have a specified widgets folder.) Right click > select User Interface > Select a Widget Blueprint.
  2. Create a new widget (there is only one default option to select).
  3. Rename the widget > E.g. > WB_VideoWidget
  4. Open Widget > Add a Canvas.
  5. Now drag in the new material from the movies folder into the widget.
  6. Resize the material box so it fills the canvas.
  7. Please note: You don’t need to add any code into the widget graph (you can if required – but this will work without any code).

BLUEPRINT:

  1. Right click in the Movie folder > Create a Blueprint > Select Blueprint Actor > Name it BP_TV or a name of your preference.
  2. The files now in your folder should show as below: Blueprint, Video, Material, Texture. Widget and Media player.

  1. In the Blueprint > Add a Box Collision > Resize as required.
  2. Right click on the collision box and select – on component begin overlap.
  3. Right click again and add on component end overlap.
  4. The player will trigger the widget to play the video full screen when they enter the collision box and it can be removed when they leave the trigger box.
  5. Drag off from the on component begin overlap node and add an Open Source node. In this node select the video in the drop-down list.
  6. Create a new variable and change it from the default Boolean to a Media player object reference.
  7. Drag this node into the graph and from the options provided select Get NewVar (or whatever you renamed it to – ideally rename to ‘Media Player’).
  8. Plug this into the target of the Open Source node.
  9. Press compile and with the Media player node selected > in the details panel > add the media player that was created.
  10. Drag off from the delay node and add a Create widget > In this node select the widget created for playing the video.
  11. Drag off this node and search for Add to viewport.
  12. Drag off from the component end overlap > Search for – Remove from parent > Drag off from ‘Return value’ of the widget node and plug into Remove from parent Target.
  13. See image below for final graph.

ADD SOUND TO THE VIDEO:

  1. Simply add a Media sound component to the component panel for the video to play sound.
  2. The component panel should like below (assuming you haven’t added other components – which if required is fine of course)

THE FINAL GRAPH:

FINISHING OFF:

  • Drag the blueprint into the level and it should work. When the player enters the collision box the video will play in the widget full screen and when the play leaves the collision box the full screen video will be removed.
  • Note: If the video doesn’t cover the entire viewport > In the widget, increase the size of the material box and make sure it overlaps with the canvas. 

Final Result

Related Video Blueprint Tutorials

This overview tutorial is part of a specific set of tutorials that relate to the upload and playing of video in Unreal Engine. Please see below the related posts in this series.

  1. How to upload and play video.

  2. How to Play video in a widget.

  3. How to Automatically Remove Video when it finishes playing.

  4. How to Disable Every Key Except One.

The post Unreal Engine – Play a Video in a Widget appeared first on Motion Forge Pictures.

Report