So my URP game compiles fine on 2021.3.14f1. However, if I upgrade my project to either 2021.3.15 or 2021.3.16 it crashes during build.
Looking at the Editor.log I get the following error before it dies:
Uploading Crash Report
NullReferenceException
at (wrapper managed-to-native)
It then follows on with a “Managed Stacktrace”
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck <0x001a7>
at DefaultBuildMethods:BuildPlayer <0x013b2>
at UnityEditor.BuildPlayerWindow:CallBuildMethods <0x0098a>
at UnityEditor.BuildPlayerWindow:GUIBuildButtons <0x026c2>
at UnityEditor.BuildPlayerWindow:ShowBuildTargetSettings <0x067a2>
at UnityEditor.BuildPlayerWindow:OnGUI <0x00f12>
I’m having the same issue so I’m staying on 2021.3.14f1 unless this gets fixed. I can build a project made with the URP template on the newer versions but when I’ve added in all of my project assets I get the same crash when building. Crashes on both Windows 11 and macOS M1 so it’s not a platform issue.
I’ve had a look through the patch notes and this change could be the cause:
2021.3.15f1:
Fixes:
Editor: Enabling shader keyword pre-filtering so that build process does not have to enumerate through full shader variant space. This fixes the issue of URP builds even with warm shader cache taking really long time. This fix does not reduce the time spent on actually compiling shaders. (UUM-3711) Unity Issue Tracker - Shader variant build preparation does not scale
I’ve also been having issue with builds only rendering light like 10% of the time. So I’m just building and building, hoping for the build that sticks.
Added: After leaving my computer off over night, the build issues I mention where I’m only having a 10% success rate at having a visible build has vanished. Just something to try if anyone sees this and is at odds.
The temporary solution is to check all your RenderFeature scripts and mark all fields of UnityEngine.Object derived types with [NonSerialized] attribute, such as:
[NonSerialized]
public Transform shadowCaster;
This is because the GatherFilterData method recursively traverses all the referenced types in the RenderAsset and retrieves their public fields or fields marked with the SerializeField attribute. However, there is a problem with the code logic written by Unity:
object value = fieldInfo.GetValue(containerObject);
if (value == null)
{
continue;
}
Type type = value.GetType();
if (value is IEnumerable)
{
IEnumerable enumerable = value as IEnumerable;
bool flag2 = settingsNode != null && settingsNode.m_Children.Count > 0;
foreach (object item in enumerable)
If the data obtained through GetValue in the first line is of the UnityEngine.Object type, Unity casts it as an object, but it is actually a “null” value in the C# object, which is != null. If the value is a Transform type object, the code will run into the foreach loop and retrieve the childCount, causing a NullReferenceException.