Invisible Sprite
My current work is an attempt to slice spritesheets using descriptive XML documents. That part appears to be working fine. I have a single Sprite object that sits in front of the camera. It shows the test sprite on the camera quite happily when I place it from the unity editor. When I try to add in the generated sprite using a component script it does not show in game.
The SpriteRenderer clearly accepts the generated Sprite since it shows in the Sprite field of the renderer when the program is run, but it won't show it on the camera. Anyone know why?
I use LateUpdate() to place the sprite in renderer.sprite if the parameters in the inspector are changed. Until the parameter is changed to an appropriate sheet the test sprite remains on the screen. Changing renderer.sprite causes it to vanish despite being a seemingly functional Sprite object. Is there something I'm missing when creating the sprite? The function I'm using provides the correct texture, a rect and the pivot. What else is there?
Also sorry if I'm slightly incoherent, I'm not used to unity terminology yet. If anyone needs clarification on something, ask away.
Posted Jun 28, 2015, 6:24 AM UTC
I've found that sprites with a z-scale of 0 often have weird behavior like that. Check the object's scale when you can't see it.
This mistake commonly occurs in my code when I set a transform scale using a Vector2 instead of a Vector3. Since they are polymorphic, there is no compiler errors but you end up with a broken scale value.
The scale remains the same regardless of if it's showing the editor-placed sprite or the generated sprite. Only the editor-placed one is shown on the camera though. The biggest change is that the generated sprite isn't named. Does it have to be named to show?
EDIT: I set the name of the generated sprite. It did nothing. Worth a try, I guess. There has to be something wrong with the way the sprite is generated, since the editor-placed sprite is sliced and placed just like the generated one, except via editor rather than code. This is driving me nuts.
EDIT2: Finally got it! It was the pivot point which I was giving in pixels rather than a float between 0 and 1. This issue had me stumped for a whole day. Thank you for the help.