0

Share

GAME DEVELOPMENT

How To Create Minimap Render Texture In Unity

  • Home
  • Blogs
  • How To Create Minimap Render Texture In Unity

A minimap displays information about the surroundings and is usually on a screen corner in video games to help players orient themselves within the game world.

Agnesh Pipaliya

July 1, 2022

You have played many video games, but while playing those games you have seen a minimap (or mini-map) in one of the corners of your game screen to guide you. 

Do you know how minimaps are developed?

Minimaps are one of the significant features of video games that guide players in finding their way and targets to achieve. On the other hand, Reder Textures are created and updated at runtime. In this blog, learn the development of the minimaps with Render Texture in Unity. Take a look.

Render Texture

The Render Texture is a type of texture that can be rendered to. Render Textures are special types of Textures that are created and updated at run time. Render Texture is used to improve and implement image based rendering, surveillance cameras, and much more.

 

 

If your game is 3D and you want to make mini map that shows where is your player as shown above image or you want to make to show any type of map, then this is the right place to learn it.

Steps To Make Minimap

If you have your own scene setup then you no need to follow these 2 steps, otherwise follow the below mentioned steps:

Step 1 - Go To Asset Store In Your Project And Find Standard Asset Package And Import This Package Into Your Current Project To Get The Readymade Scene.

Step 2 - After Importing This Package, Find The Scene Name With “Car” And Double Click On That Scene To Open It.

To make minimap, we need a second camera that can renderer our scene from a top-down view.

To do that let’s deselect everything and right-click in our hierarchy and select Camera, rename it as “Minimap Camera" let’s then reset the transform on our camera.

 

 

Note - In my case, I supposed to “Car” as my “Player”. Now I want to show where is my Player(Car) in the mini-map.

 

 

Step 3 - Now I Am Just Making My Camera Follow The Car From Top So I Just Copy Player(Car) Transform Component And Paste On Our Minimap Camera Transform.

Now set camera transform as shown below figure.

 

 

Now set our Minimap Camera’s Projection in Orthographic and Size that you want to show how your camera see from that height.

In my case set its Size 13 as shown below figure.Make sure that our camera sits at the same position as our Player.

 

 

Step 4 - Right Click On Hierarchy And Create Raw Image.

 

 

Now we can switch to 2D mode and hit “F” to focus on a Raw Image now a raw image is basically like any other UI image component except it takes in a texture instead of a sprite.

 

 

This is good because basically we are going to tell our Minimap Camera to take everything it renders and put it into a texture this is called a render texture we can then take that texture and display it on a Raw Image.

Let’s select our 2d controls and let’s zoom out a bit and now we can position our mini map where we want it. I’m gonna

Anchor mine to the top right. And set its transform as shown below image, so it can be visible on the top right corner of the UI Canvas.

Now i’m just set my raw image transform as shown below figure but you can free to set its transform as your requirement.

 

 

 

 

So now in our game view we should see a white square in the right corner of where our mini-map is going to be but of course we still need to display our texture.

Step 5 - To Do That We Create A New Render Texture. As Shown Below Image Let’s Go To The Project, Right- Click Here Go Create And Now Select Renderer Texture And Renamed It As Our MinimapRenderTexture.

 

 

 

 

Here as shown below image we have a bunch of texture setting we’re gonna leave pretty much all of them as it is. You can learn more about renderer texture from below mentioned link:

https://docs.unity3d.com/Manual/class-RenderTexture.html

 

 

First of all, set the size to the same as our raw image let’s set it to 123 by 123 and we can also disable our depth buffer as shown below image.

 

 

Step 6 - If We Now Select Our Mini-Map Camera We Can See As Shown Below Image That There Is A Target Texture Variable And This Takes In A Render Texture Let’s Drag Our Minimap Render Texture Into That Target Texture Variable Box And You Can See Now That Our Game View Switches Back To Our Main Camera So Our Minimap Camera Is No Longer Rendering On Screen.

 

 

 

 

Now select our Raw Image and drag our MinimapRenderTexture as the texture input in Raw Image.

 

Now you can see as shown below image that our camera is now rendering directly onto the screen as a UI element now we can rename this Raw Image to our Minimap.

 

Let’s run the scene and start moving the car around the scene you can see our car is moving around but our Minimap isn’t following our Player(Car) yet but we can add this very easily.

 

 

Step 7 - Now Create A New C# Script And Call It Minimap And Add A Copy Of The Below Code On That Script.

 

 

Apply this script to our Minimap Camera and assign our Player transform reference from hierarchy and run the seen, by moving of our player you can see that our minimap actually follows our player.

 

 

Conclusion

Now you have learned the creation of a minimap in Unity. There are still many things to learn to create a complete minimap for a video game. 

We have created a blog on the Minimap to give you a basic idea of making a Minimap using Render Texture in Unity and to help you in your various game development projects. 

img

Agnesh Pipaliya

COO of Vasundhara Infotech, a leading Software development company in the USA. His technological interests has helped the company in making useful decisions.

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Latest 13 Web Development Trends To Expect In 2022
April 11, 2022 Category : company news

Revealing Vasundhara’s New Identity

Read More
Latest 13 Web Development Trends To Expect In 2022
May 17, 2022 Category : web development

Latest 13 Web Development Trends To Expect In 2022

Read More
Leave a Comment