- Home /
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.
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.
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.
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...