• 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
0
Question by anto_skillveri · Dec 08, 2017 at 11:13 AM · gameobjectsprite

How to combine sprites together dynamically?

Is there a way to combine multiple sprites into a single sprite dynamically(say, when the sprite count reaches 500 or so). The game object we use consists of a sprite renderer which has a sprite attached to it. When i run my application the gameobject keeps on increasing and ideally we will have about 1200 gameobjects in our scene at runtime. When the count goes to 4000, the fps is dropping drastically to 15 fps. Is there a way to reduce this number by combining the objects together at runtime.

Comment
Add comment · Show 1
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 LilGames · Mar 19, 2018 at 05:22 PM 0
Share

Have you looked into Batching? How many Draw Calls are you seeing?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Cavite8567 · Mar 19, 2018 at 05:04 PM

Yes, sort of, I'm not sure if this is the best method but you can create a new Texture that is as tall as the sprites added together vertically, and as wide as the textures added horizontally. This script will make the objects texture equal to the texture of tex1 on the bottom and tex2 on the top. Also keep in mind that both textures have to be read and writeable. Hopefully this helps!

  using UnityEngine;
  using System.Collections;

  public class DynamicSprites : Monobehavior {

       public Texture2D mainTex;
       public Sprite tex1;
       public Sprite tex2;

       void Update()
       {
             for(int x = 0; x < tex1.width; x++)
             {
                   for(int y = 0; y < tex1.height; y++)
                   {
                        mainTex.SetPixel(x,y,tex1.GetPixel(x,y));
                   }
             }
             for(int x = 0; x < tex2.width; x++)
             {
                   for(int y = 0; y < tex2.height; y++)
                   {
                       // Add the height or width of the first image to either the x or y, in this case y because the texture will be on top.
                        mainTex.SetPixel(x,y + tex1.height,tex1.GetPixel(x,y));
                   }
             }
             mainTex.Apply();
             GetComponent<SpriteRenderer>().sprite = Sprite.Create(mainTex, new Rect(0,0,mainTex.width,mainTex.height), Vector2.zero);
       }
  }








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 Tholem · Mar 13 at 08:17 PM 0
Share

I get this error "Texture 'Checkmark' is not readable, the texture memory can not be accessed from scripts." when I try GetPixel()

avatar image LilGames Tholem · Mar 13 at 08:22 PM 0
Share

Turn on "Read/Write" for that texture, in import settings.

avatar image Tholem LilGames · Mar 20 at 03:03 PM 0
Share

Yes, or you can use this too: https://answers.unity.com/questions/988174/create-modify-texture2d-to-readwrite-enabled-at-ru.html

avatar image
0

Answer by viku_99 · Feb 05, 2019 at 09:22 AM

Assign camera and render texture and render it in new raw image or image and you will save those combine sprites.@anto_skillveri

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

125 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing the alpha channel of a sprite using the new Unity sprite system 1 Answer

check the presence of desired sprite in canvas on click? 0 Answers

My sprite does not change 1 Answer

Unity OnMouseDrag too fast for Update function 0 Answers

Animator - Stoping && Playing from Specific frames. 5 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