Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 minipog · Jan 28, 2014 at 08:58 PM · spritemultiplespriterenderertile

Assign multiple sprites to a renderer, or assign multiple renderers to single object

If I want to make a tilemap, with sprite Assets consisting of multiple tiles, I need to be able to adequately sort each tile sprite depending on its position on the isometric grid (thus "cutting" the sprite Asset in tile units).

To achieve this, a simple solution would be to create one gameobject per tiled sprite, and track its transform.position. Problem is the scene could rapidly get crammed with gameobjects.

Thus my idea was to get a single gameobject (the sprite Asset) to render multiple sprites (one sprite per tile occupied). To my knowledge, it is impossible to either :

  • get a single gameobject to use two different sprite renderers each assigned with rendering a different sprite (tile).

  • get a single sprite renderer to render multiple sprites at the same time, each being assigned a different sorting order.

Is there a way out of this plight? Or is having a plethora of gameobjects in a scene not really an issue performance-wise?

Comment
Add comment
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

1 Reply

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

Answer by supernat · Jan 29, 2014 at 07:16 AM

Having tons of game objects will always be an issue performance-wise and death if you're doing mobile. You will want to create a single quad that has a vertex at every tile corner, and just set the texture coordinate for that vertex to the texture coordinate of that tile for that corner. I'm not sure what you mean by sprite rendered as sprite is a rather generic term. Are you using a particular sprite system (like 2DTK?)

My suggestion is that while it's a good exercise in learning, it'd be way more efficient to purchase a plugin from the Asset Store to do this for you. Otherwise, you'll want to create a dynamic vertex buffer at runtime and set the texture coordinates for each tile in the buffer. Then as you move through the world, you would load up new quads in front of you and unload old ones that are out of sight.

Comment
Add comment · Show 3 · 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 minipog · Jan 29, 2014 at 07:18 PM 0
Share

What I should have said sooner is that this project is actually based on the isometric view. What I have coded so far is a SpriteAsset importer that creates prefabs based on the data stored in a xml file this way :

  • Cut asset in tile width sized sprites

  • Draw each tile-sized sprite with correct offset (start with the top left most one, end with the bottom right most one)

  • Group all these sprites in a single gameobject

  • Sort each sprite order based on its position in the isometric grid (bottom-right is higher, top-left is lower) granting me the ability to have assets more than one unit tall to overlay parts of each other depending on their position.

This method gives me incredible ease in the editor when it comes to building a level, as I can freely adjust a sprite asset position, flip it... The idea was actually to get something similar to the Shadowrun Editor (video here).

The idea of a single mesh is way better performace-wise but would not, in my humble opinion, offer such ease-of-use. Nonetheless, I think I'll use this technique when it comes to making the ground of the level (representing the vast majority of tiles in the level, thus reducing the gameobjects count ALOT).

I apologize if I don't make much sense, but (1) I am new to all this coding poetry, and (2) English ain't my first language.

avatar image sdgd minipog · Jan 29, 2014 at 07:19 PM 1
Share

please don't post answers as comments.

avatar image supernat · Jan 29, 2014 at 11:23 PM 0
Share

Sorry, I assumed you were just creating a single layered ground map from tiles. You may have a nice balance to have the ground layer be a single mesh (or large mesh chunks that are dynamically loaded/unloaded) and to use objects for detail sprites like mountains, characters, buildings, etc.

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

How to correctly use SpriteRenderer with multiple sprites (if possible) 0 Answers

How to truncate sprite without changing the scale of the sprite? 1 Answer

Need help with size of Tiles! 2 Answers

How do you load a single sprite from a multiple sprite sheet with script? 1 Answer

Sprite Mask Render Issue 1 Answer


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