• 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 $$anonymous$$ · May 04, 2015 at 03:38 PM · 2dgraphicsspriterenderer

Instantiated SpriteRenderer not rendering sprite

I am currently instantiating a prefab object with a SpriteRenderer in the editor and then setting its sorting layer and sprite through code. The sprite is loaded from a sprite sheet in a Resources folder.

Everything works fine when I drag the prefab from the folder into the scene. However when I instantiate the object through code the sprite does not render.

In the inspector both the sorting layer and sprite have been set correctly and the sprite renderer is enabled but the sprite does not appear in the scene view or in game.

alt text

After the object has been instantiated I have tried changing the sprite manually, enabling and disabling the SpriteRenderer, removing and re-adding the SpriteRenderer and changing the Sorting Layer but nothing seems to make the sprite render until I completely delete the object and drag another one into the scene view.

Has anyone encountered a similar issue with instantiated SpriteRenderers?

To summarize:

  • The code has been designed to run in both the editor and runtime

  • The objects are being instantiated correctly

  • The sprites and sorting layers are being set correctly (as seen in the inspector)

  • The sprites are not rendering in game or in the scene view

Any help to getting my SpriteRenderers to start rendering again would be greatly appreciated!

Update:

The code that sets the sprite and sorting layer: http://pastebin.com/w1Zw5fVg

The code that spawns the object: http://pastebin.com/74exK29b

Note I'm using SimpleJSON to get the data for the object.

static-graphics-object.png (73.2 kB)
Comment
Add comment · Show 3
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 $$anonymous$$ · May 04, 2015 at 12:49 PM 0
Share

If you need to see any code feel free to ask.

avatar image DoTA_KAMIKADzE · May 04, 2015 at 02:01 PM 0
Share

Yes - the code will be needed. Update your answer with the code that shows how you instantiate and then change values of SpriteRenderer inside your instantiated object.

avatar image $$anonymous$$ · May 04, 2015 at 02:54 PM 0
Share

Ok links have been added to the relevant code.

1 Reply

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

Answer by $$anonymous$$ · May 05, 2015 at 02:09 PM

And I'm an idiot!

Sometimes you just need a little time doing something else it seems. Turns out I was setting the x and y scale of of the object to 0 without realizing...

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

2 People are following this question.

avatar image avatar image

Related Questions

2D Sprite Graphics Glitching, Skewing, Flickering, Crazy, Haywire 1 Answer

Switching between 2D and 3D in the same Scene 2 Answers

How to make a sprite invisible yet still opaque? 1 Answer

Render particles in front of any sort layer (2D sprites) 3 Answers

infinite 2d grid in an Editor Window 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