Skip to main content
Minor grammar fixes
Source Link
liggiorgio
  • 5.5k
  • 6
  • 27
  • 38

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 programmicallyprogrammatically 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 programmmicallyprogrammatically 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 Sprite RendererSpriteRenderer 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?

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 programmically 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 programmmically 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 Sprite Renderer 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?

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?

Source Link

How to Force Refresh Texture2D/Sprite when Programmically Modified using Editor Script?

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 programmically 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 programmmically 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 Sprite Renderer 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?