Unity 2019.3.12f1 New Project Build NullReferenceException Causes only Background Color to Render
Hello Everyone! I'm new to Unity 2019.
When I make a 2d project, put one GameObject into the scene and run it, I can see it when I preview the game. When I build the game on Windows 32, 64, or WebGL, I get a blue screen - or whatever the background color of the camera is. If I decide to add audio, that will play, but the graphics will not render. In build settings, I select the scene to add to the build. I have created new scenes and new projects to try that as well. All to no avail.
I have seen several of these issues posted, but either they are never resolved, or the issue is trivial and not relevant to me. I ran in debug mode (because I wanted to see what the problem is) and I get a NullReferenceException
. Please note that I have not written any scripts. Only added a single sprite.
I looked in the logs and found this repeated a million times:
NullReferenceException: Object reference not set to an instance of an object
at Unity.Collections.NativeSlice`1[T].get_Item (System.Int32 index) [0x00001] in C:\buildslave\unity\build\Runtime\Export\NativeArray\NativeSlice.cs:200
at UnityEngine.U2D.SpriteShapeGenerator.TessellateContour () [0x00192] in C:\Unity\Breakout2\Library\PackageCache\com.unity.2d.spriteshape@3.0.10\Runtime\SpriteShapeGenerator.cs:1001
at UnityEngine.U2D.SpriteShapeGenerator.Prepare (UnityEngine.U2D.SpriteShapeController controller, UnityEngine.U2D.SpriteShapeParameters shapeParams, System.Int32 maxArrayCount, Unity.Collections.NativeArray`1[T] shapePoints, Unity.Collections.NativeArray`1[T] metaData, UnityEngine.U2D.AngleRangeInfo[] angleRanges, UnityEngine.Sprite[] segmentSprites, UnityEngine.Sprite[] cornerSprites) [0x00051] in C:\Unity\Breakout2\Library\PackageCache\com.unity.2d.spriteshape@3.0.10\Runtime\SpriteShapeGenerator.cs:2073
at UnityEngine.U2D.SpriteShapeController.BakeMesh (System.Boolean needUpdateSpriteArrays) [0x00371] in C:\Unity\Breakout2\Library\PackageCache\com.unity.2d.spriteshape@3.0.10\Runtime\SpriteShapeController.cs:479
at UnityEngine.U2D.SpriteShapeController.OnWillRenderObject () [0x0002d] in C:\Unity\Breakout2\Library\PackageCache\com.unity.2d.spriteshape@3.0.10\Runtime\SpriteShapeController.cs:351
(Filename: C:/buildslave/unity/build/Runtime/Export/NativeArray/NativeSlice.cs Line: 200)
I have no idea where to go from here. I have searched the web extensively. Any help would be appreciated. I have a Zotac GTX 1060 Ti 6gb graphics card, by the way.
Answer by Venkify · May 20, 2020 at 07:07 AM
Sorry for the delay in response. We do frequently try to respond in forums.
@dandeto @kalle18 Please ensure that you have a valid SpriteShape profile set in the SpriteShapeController. A simple SpriteShape profile with a 4x4 white texture set to repeat mode as fill texture can be set to these objects. We have addressed this issue and added a warning if a valid Profile is not set in recent versions.
@dandeto SpriteShape data is stored in a very compact form and the geometry is only generated once on the Runtime as long as there are no changes. It is generally fast and when Burst package is installed its quite faster as it utilizes C# jobs to generate the geometry. Could you kindly provide a simple repro project where is slow. We will try to take a look asap.
Sorry for the inconvenience caused.
This was the solution for me. I was using Sprite Shape Renderer without a profile and it worked great in the Editor but it didn't wok in the Android build. I just created a new profile and set it to the Sprite shape renderer, now it works like a charm.
Answer by dandeto · May 03, 2020 at 05:54 PM
UPDATE
I looked at the logs more and experimented. I removed everything from the scene except for the camera. When I made my test scene, the ONE gameobject I decided to put in the scene was a SpriteShape. I removed it and added a single sprite. The game built and rendered like normal with no errors.
So here is a follow up question based on my new findings: Why in the world does Unity break the build when I have a spriteshape in my scene, but it is fine with any other object. Furthermore, why does the console not throw any errors when I preview the game?
I'm not really sure what the difference between a sprite and spriteshape is, I just wanted to draw shapes in a little test 2D game because I didn't have any actual sprites drawn.
I will reinstall Unity to see if that fixes anything because this behavior seems wildly broken. Please correct me if I'm wrong.
Unforunately I don't have the answer for you, but I can feel with you. I can confirm the same behavior.
I have a little 2D prototype, mixed with sprites AND spriteshapes (not quite sure what the difference is either). I used the spriteshape for a dynamic background color of sprites. I've chosen the spriteshape because you can make some shape with a defined color and don't need to provide any image, so it was just for quick prototyping.
I can run the game in preview mode but once I build the game (Windows x64) I get NullReferenceExceptions and no spriteshapes are rendered:
NullReferenceException: Object reference not set to an instance of an object
at Unity.Collections.NativeSlice`1[T].get_Item (System.Int32 index) [0x00001] in C:\buildslave\unity\build\Runtime\Export\NativeArray\NativeSlice.cs:200
at UnityEngine.U2D.SpriteShapeGenerator.TessellateContour () [0x00192]
Quick for prototyping - exactly why I chose spriteshape! It actually made my game lag on top of not building. I converted everything to sprites and it runs so much nicer and will build. I'm glad you confirmed that it's an issue, though.
The SpriteShapes are crashing my project as well with same error but on an Android Build. It's depressing, because I was just moving all my assets from Ferr2D to Sprite Shapes; and as like with another 2D features, - like Anima2D - I have the feeling they are being sloppy and unfocused with 2D libraries.
I'd try to Report a Bug, but it's so much job. If I don't find any other thread with the solution I'll have to do it.
Answer by oriolmanya · May 17, 2020 at 09:56 PM
Hi guys, as I said in the comment, It happens to me as well when publishing on Android .
So I sended a Bug Report (with code case 1248133)
I started this thread in the forum to know if more people are experiencing the problemand give awarenes to this error that I judge critical:
Forum link: https://forum.unity.com/threads/sprites-shapes-crash-on-android-build-v-2019-3-13.892567/
[Edit] Solution:
I quote as @Venkify from Unity answered me in the forum, and it worked:"Please ensure that you set a valid SpriteShape profile for all the SpriteShapeController Objects in the scene. This should fix the issue. In Editor, we allow editing SpriteShape without having a valid SpriteShape profile to prototype easier. But a valid SpriteShape profile is required to be set for runtime to render properly. A simple SpriteShape profile with a 4x4 white texture set to repeat mode as fill texture can be set to these objects."
Your answer
Follow this Question
Related Questions
Build button is greyed out for Universal Windows Platforms 0 Answers
My builded game is resized! 1 Answer
how can i fix building game? 1 Answer
Unity build only ask's permission on android publish but not when I build and test? 0 Answers
Unity Start not called on build, but it does when testing 0 Answers