Here is some code called using a custom button in the component inspector:

// created off-screen:
// Texture = Texture2D, width = int, height = int

SpriteRenderer.sprite = Sprite.Create(Texture, new Rect(0, 0, width, height), new Vector2(0, 0));

Long story short, I am programmatically creating a Texture2D and applying it to my SpriteRenderer. I 100% know the code works because, once I run the game, the SpriteRenderer displays the exact Texture2D I programmatically created. The issue is when I click my "generate" button in the component inspector, the texture is not displayed in the scene.

When I click on my SpriteRenderer in the inspector, I can see a "box" representing the texture's bounds as if it's not loaded? The size changes for each generation, so I know it knows the size of the texture? But I can't find a way to force it load except for actually running the game. Once I run the game, the texture displays just fine. Even after I stop the game, the editor shows the texture just fine until I generate it again. As if there's something about running the game that refreshes it?

Is there something I'm missing? Something to force the scene or SpriteRenderer to display in editor?


1 Answer 1


Had to call Texture2D.Apply() after modifying the texture using SetPixel. Whoops.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .