Search Issue Tracker
Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.
Postponed
Votes
13
Found in
2017.4.0f1
2018.3.0a1
2018.3.0f2
2019.1.0a1
Issue ID
1110225
Regression
No
NullReferenceException from GenerateTiledSprite when SpriteAtlas is not included in the build and Image Type is set to 'Tiled'
How to reproduce:
1. Open user-submitted project (IssueRepeatedImageWithSpriteAtlas) and 'SampleScene' scene
2. Enter Play Mode
Expected result: no errors are displayed in the Console window
Actual result: NullReferenceException is displayed in the Console window
Reproducible with: 2017.4.18f1, 2018.3.1f1, 2019.1.0a13
Notes:
'Image Type' must be set to 'Tiled'
'Include in Build' option on the SpriteAtlas must be unchecked
-
mWundke
Sep 01, 2021 07:05
We fixed the issue using our own Image component with the following changes to it's OnPopulateMesh method:
/// <summary>
/// Our UI Image component fixing the Tiled Image and Sprite Late Binding bug
/// </summary>
public class Image : UnityEngine.UI.Image
{
/// <summary>
/// Update the UI renderer mesh.
/// </summary>
protected override void OnPopulateMesh(VertexHelper toFill)
{
// In tiled mode we have to ensure we have a valid Texture. This is to prevent the following bug
// https://issuetracker.unity3d.com/issues/nullreferenceexception-from-generatetiledsprite-when-spriteatlas-is-not-included-in-the-build-and-image-type-is-set-to-tiled
if ((overrideSprite != null && overrideSprite.texture == null) && type == Type.Tiled)
{
OnPopulateMeshForTiledImageBug(toFill);
return;
}
base.OnPopulateMesh(toFill);
}
/// <summary>
/// Copied from UnityEngine.UI.Graphic to solve:
/// https://issuetracker.unity3d.com/issues/nullreferenceexception-from-generatetiledsprite-when-spriteatlas-is-not-included-in-the-build-and-image-type-is-set-to-tiled
/// </summary>
/// <param name="vh"></param>
private void OnPopulateMeshForTiledImageBug(VertexHelper vh)
{
var r = GetPixelAdjustedRect();
var v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);Color32 color32 = color;
vh.Clear();
vh.AddVert(new Vector3(v.x, v.y), color32, new Vector2(0f, 0f));
vh.AddVert(new Vector3(v.x, v.w), color32, new Vector2(0f, 1f));
vh.AddVert(new Vector3(v.z, v.w), color32, new Vector2(1f, 1f));
vh.AddVert(new Vector3(v.z, v.y), color32, new Vector2(1f, 0f));vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
}
} -
tarpaha
Aug 31, 2021 20:07
Also got this exception.
Unity, you need to changeif (activeSprite != null && (hasBorder || activeSprite.packed || activeSprite.texture.wrapMode != TextureWrapMode.Repeat))
to the
if (activeSprite != null && activeSprite.texture != null && (hasBorder || activeSprite.packed || activeSprite.texture.wrapMode != TextureWrapMode.Repeat))
In the Image.cs
-
joe_nk
Jul 21, 2020 21:04
I'm seeing this too in 2019.4.1f1. I'm a bit miffed as to why a common, easily reproducible crash has been considered low priority?
-
jason_unity266
Oct 21, 2019 21:22
2019.2.6f1
-
MikePage_Artrix
Sep 09, 2019 00:36
you can get around this by ensuring the atlas is loaded before the call to GenerateTiledSprite
-
MikePage_Artrix
Sep 04, 2019 05:09
2019.2.2
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Average FPS in Play Mode degradation on a newly created BiRP project when it's upgraded from 2020.3.48f1 to a newer Editor version
- DecoratorDrawer indentation is incorrect when it is called with EditorGUI
- Error "InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings." is present when using UI Toolkit and New Input System
- "Unable to get the list of approved APIs." is thrown when testing the App Packages with Windows App Certification Kit
- [Linux] The mouse wheel input is inverted when scrolling in the Build
Resolution Note (2019.2.X):
As noted the ticket is low priority and they deemed we can close the case. Not sure why it was triggered as high priority.