How to make a world space UI in Unity

Some games have the health bar of the player or the enemy on top of the character’s head. Want to implement that in your game? You have come to the right tutorial. By default, Unity Ui is on the screen space overlay i.e. The UI is on top of everything. No matter how you move the character the UI still remains the same. To make the UI part of the game you need to change the render to World space.

In this tutorial, we will see how to create a world space UI and adjust it to remain on top of the game object.

We have a cube in our scene. We are going to add a UI text that represents the name of the gameobject.

Select the gameobject to which you want the UI to be attached.

Right click>UI>text. (You can add the UI element of your choice)

This adds a Canvas and an event system. The canvas is added as a child of your gameobject.

Unity hierarchy view

Select the Canvas

Go to the Inspector window.

Select the render mode as World space and drag and drop the main camera as the event camera

Canvas render setting

Now the canvas is like any other gameobject in your scene.

Adjust the position, height and width of the canvas to your requirement.

Once the Canvas is in place. Set the UI element position to 0,0,0.

Do not adjust the width and height of the UI element. You need to change the transform scale to adjust the size of the UI element.

Since your canvas is a child of the cube the UI will move with the cube.

Gameobject with worldspace UI

If you want to know how to create a health bar, check out our tutorial on creating a health bar in Unity. If you have any other questions leave them in the comment box below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.