Null ref exception inside PolySpatialAssetBuildProcessor.cs OnProcessScene


I really need to raise this again, my last post fizzled out, but this issue is a quick fix on the PolySpatial side, yet is causing huge issues for us, as every time a new version of PolySpatial drops we need to:

  • Move the package source code (so it doesn’t get clobbered)
  • Re-instate our code fix
  • Fix dozens of lines of PolySpatial code that make assumptions about the location of the PolySpatial packages.

So, in our game we build asset bundles, and as part of that, we need to call BuildPipeline.BuildPlayer(), so that we can then grab the types and use them to check for dependencies. There’s nothing unusual about it; it’s just calling BuildPlayer() outside the narrow use case of producing a build.

Unfortunately, PolySpatialAssetBuildProcessor.cs makes hard wired assumptions that you’re only building the list of projects in the BuildSettings window etc, as a result, there is a crash inside OnProcessScene that we cannot work around short of changing the source code. All we need the PolySpatial team to do is, check against null and check against the empty dictionary case inside s_SceneAssets, like so:

        public void OnProcessScene(Scene scene, BuildReport report)

	        if (!BuildPipeline.isBuildingPlayer)

	        if (s_SceneAssets == null)

	        if (s_SceneAssets?.TryGetValue(scene.path, out var guids) != true)
		        Debug.LogWarning("PolySpatialAssetBuildProcessor.OnProcessScene skipped");
	        var guids = s_SceneAssets[scene.path];

	        var qam = new GameObject().AddComponent<PolySpatialSceneAssetMap>();
	        qam.m_SerializedAssetGUIDMap = new List<PolySpatialSceneAssetMap.AssetGUIDMapEntry>(guids.Select(agme =>
		        new PolySpatialSceneAssetMap.AssetGUIDMapEntry
			        locator = agme.asset.locator,
			        obj = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(agme.guid))
	        ).Where(agme => agme.obj != null));

This fix is simply to check your objects before using them, and by doing this, will reduce the pain considerably on our side, and for anyone who ever calls BuildPlayer outside the narrowlly assumed use case it currently is.

Thanks in advance,


Note: My original thread was in:

Please file a bug and post the incident id here. That way we can get this issue raised and scheduled internally.