Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by klolololol · May 07, 2015 at 10:00 AM · performancetexture2dminimap

Creating minimap best performance

I want to create a Minimap from an int[][] array. A "pixel" on the Minimap has 3 possible states:

  1. dark brown

  2. brown

  3. light brown

I see two options:

  1. create the Minimap from small sprites, and dynamically change their SpriteRenderer's sprite on each frame.

  2. dynamically create a texture on each frame, and apply this texture to the Minimap's Sprite.

Which is better if we consider performance?

If the second one, please provide me some optimized code.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image komodor · May 07, 2015 at 10:25 AM 0
Share

isn't possible to use classic way and just use camera with culling mask and render it to texture? you can use shader to get the colors you want

the sprite flipping option sounds pretty weird to me and the texture generation is pretty expensive

avatar image klolololol · May 08, 2015 at 10:21 AM 0
Share

not possible since it's a tile based game and the whole map is never visible

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Baste · May 07, 2015 at 01:40 PM

Use one Texture2D that takes the entire space of the minimap, and use SetPixel to write the color to the pixel coordinates that match your array's index. Remember to Apply after you've changed all of the pixels you have changed.

This is essentially option 2, but without creating a new texture every frame, which would create memory garbage really, really fast.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image klolololol · May 07, 2015 at 05:18 PM 0
Share

Could you provide some code please? I've tried this, but I got !hasError error, what I really don't know what is.

Code:

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$ini$$anonymous$$ap : $$anonymous$$onoBehaviour {
 
     public SpriteRenderer myRenderer;
 
     Texture2D texture;
     Sprite sp;
 
     void Start() {
         texture = new Texture2D(100, 100);
     }
 
     void Update() {
         for(int i = 0; i < 100; ++i) {
             for(int j = 0; j < 100; ++j) {
                 texture.SetPixel(i, j, new Color(1, 0, 0, 0));
             }
         }
 
         // Apply all SetPixel calls
         texture.Apply();
         sp = Sprite.Create(texture, new Rect(100, 100, 100, 100), new Vector2(0, 0));
         myRenderer.sprite = sp;
     }
 }
 

Full error message:

UnityEngine.Sprite:Create(Texture2D, Rect, Vector2) $$anonymous$$ini$$anonymous$$ap:Update() (at Assets/Scripts/GameUI/$$anonymous$$ini$$anonymous$$ap.cs:24)

avatar image klolololol · May 08, 2015 at 10:18 AM 0
Share

ok it turns out you have to use normalized values in Sprite.Create, now I did it like this:

         sp = Sprite.Create(texture, new Rect(0, 0, 0.5f, 1f), new Vector2(0.0f, 0.0f), 0.1f);

I still have problems with the result, but that's an other topic

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't copy skybox faces to a cubemap sized texture without huge quality loss 0 Answers

iOS OnGUI vs Update for color picker 2 Answers

Non-blocking construction (loading and copying) of large Texture2D's in C# 1 Answer

How to make a minimap like in rogue legacy? 0 Answers

Exploding texture into it's individual pixels 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges