Virtual Reality (VR) game development is much different from regular game development. For example, something like a basic head-up display (HUD) to show some stats would work fine in a regular game, but not in VR. In fact, standard HUD would cause rendering issues because it adds itself to the Viewport.
So how can you use HUD in VR then? In this post, I will go over a way for you to bring your HUD into 3D space for Unreal Engine 4 (UE4).
In this post, I am assuming you have some familiarity with UE4 already. Here are some terminologies:
- HUD ↔ User Interface, User Widget
- 3D HUD ↔ WidgetComponent in a Blueprint
- 3D space ↔ World
Note: the left-hand side is more generic, while the right-hand side is UE4
Creating a standard HUD
Create your HUD while keeping in mind two things. First is you need to account for the visibility of your HUD in VR. Second is you need to change the size of the HUD to be a custom size. The width and height are completely up to you; just make sure it has good visibility in VR.
For tips about how things are best viewed in VR, you can visit my post about Virtual Reality development with Unreal Engine 4. Specifically, you will want to go over the Best Practices for Virtual Reality section.
Here is an example User Widget with custom size settings:
Creating a 3D HUD
If you use your standard HUD and preview it in VR, you will notice the HUD will not be visible or cause rendering issues. For you to use your standard HUD, you must bring it into 3D space (world).
An easy way to do this is to create an empty Blueprint Actor class. In your Blueprint Actor, add a new component call “Widget“. Select the widget component and in the Details tab navigate to User Interface. Set the Widget class to your standard HUD class. Then change the Drawing Size to match your HUD. The X corresponds to the width and Y corresponds to the height.
Here is an example Blueprint Actor with a widget component that is all set up:
Adding 3D HUD into World
There are two ways to add your 3D HUD into the world. One way is to simply drag the HUD into the world editor and then place it where you want. The only disadvantage to doing this is that the HUD is only visible at that specific location in the world.
Another way is to spawn the HUD dynamically from some sort of user input. For example, you can have the left trigger of the VR controller spawn the HUD near the player. This way the player can always bring up the HUD when they need to.
Here is an example of dynamically spawning a HUD near the player in Blueprint:
I hope you found this post helpful. If you found this post helpful, share it with others so they can benefit from this post too.
Was there anything I left out, that you think I should talk about? Feel free to leave a comment.
Also, to stay in touch, you can follow me on twitter.
Pingback: The Components That Makes up a Great Virtual Reality Experience - bright developers
Pingback: Creating Interactive HUDs for Virtual Reality with Unreal Engine 4 - bright developers