#Editor error with AsyncLoadSceneOperation

1 messages · Page 1 of 1 (latest)

fallen berry
#

What could be the cause of this error? It appears each time I open the project or about to enter play mode.

NullReferenceException: Object reference not set to an instance of an object
Unity.Scenes.AsyncLoadSceneOperation.ScheduleSceneRead () (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Scenes/AsyncLoadSceneOperation.cs:416)
Unity.Scenes.AsyncLoadSceneOperation.UpdateAsync () (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Scenes/AsyncLoadSceneOperation.cs:354)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/Stubs/Unity/Debug.cs:17)
Unity.Scenes.SceneSectionStreamingSystem:UpdateLoadOperation(SystemState&, AsyncLoadSceneOperation, World, Entity, Boolean) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Scenes/SceneSectionStreamingSystem.cs:655)
Unity.Scenes.SceneSectionStreamingSystem:ProcessActiveStreams(SystemState&) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Scenes/SceneSectionStreamingSystem.cs:494)
Unity.Scenes.SceneSectionStreamingSystem:OnUpdate() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Scenes/SceneSectionStreamingSystem.cs:828)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:723)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:681)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:723)
...
cursive dragon
#

did you reference a gameobject you also baked?

fallen berry
#

what do you mean?

cursive dragon
#

AddComponentObject(entity, authoring)

#

something like that

#

the tldr somehow an asset you are referencing didn't make it into the build

fallen berry
#

Yes, an editor script

#

This

[DisallowMultipleComponent]
public class EditorDynamicAIMeshAuthoring : MonoBehaviour
{
#if UNITY_EDITOR
    private void OnValidate()
    {
        if (TryGetComponent(out MeshFilter _) && TryGetComponent(out Renderer _)) return;
        Log.Error($"This component on gameobject {name} must have a mesh filter and a renderer!");
    }

    private class AuthoringBaker : Baker<EditorDynamicAIMeshAuthoring>
    {
        public override void Bake(EditorDynamicAIMeshAuthoring authoring)
        {
            Entity entity = GetEntity(TransformUsageFlags.None);
            EditorDynamicAIMeshComponent authoringComponent = new()
            {
                m_Mesh = authoring.GetComponent<MeshFilter>().sharedMesh,
                m_Renderer = authoring.GetComponent<MeshRenderer>(),
                Position = authoring.transform.position,
                Scale = authoring.transform.localScale,
                Rotation = authoring.transform.rotation
            };
            AddComponentObject(entity, authoringComponent);
        }
    }
#endif
}

#if UNITY_EDITOR
public class EditorDynamicAIMeshComponent : IComponentData
{
    public Mesh m_Mesh;
    public Renderer m_Renderer;
    public float3 Position;
    public float3 Scale;
    public quaternion Rotation;
}
#endif
cursive dragon
#

m_Renderer = authoring.GetComponent<MeshRenderer>(),
yeah this

#

though hmm your wrapping i woudl have thought would stop a build breaking

#

but question, is this error in a build or editor?

fallen berry
#

Editor

cursive dragon
#

yeah so meshrenderer doesn't exist anymore

#

once it's been baked

#

the gameobject is destroyed and all its components

fallen berry
#

I see.

#

okay thanks, I will check for null reference before assigning it

#

This is weird, I tried this:

if (!authoring.TryGetComponent(out MeshFilter meshFilter) || !authoring.TryGetComponent(out Renderer renderer))
{
    Log.Error($"GameObject {authoring.name} must have a MeshFilter and a Renderer component.");
    return;
}
Entity entity = GetEntity(TransformUsageFlags.None);
EditorDynamicAIMeshComponent authoringComponent = new()
{
    m_Mesh = meshFilter.sharedMesh,
    m_Renderer = renderer,
    Position = authoring.transform.position,
    Scale = authoring.transform.localScale,
    Rotation = authoring.transform.rotation
};
AddComponentObject(entity, authoringComponent);

still didn't work

cursive dragon
#

it's not null here

#

it's null when baking finishes

#

this code runs, it exists

#

when this finishes running, its destroyed

#

so your error is on the deserialization of the subscene trying to get a reference to an object that doesn't exist

#

unityObjectRefs[i] = objectReferences[i].GetInstanceID();
the object ref is now null so it cant get the instance id

fallen berry
#

any ideas how to fix this? never encountered it before... I guess I'm not fully sure how the baking process works

cursive dragon
#

the answer is you can't do what you're doing

#

nothing more

#

i'm not sure what you're doing so i can't really suggest an alternative

fallen berry
#

Well, this baker script is supposed to store values into the EditorDynamicAIMeshComponent comonent so that I can write another editor script that will look at the values of EditorDynamicAIMeshComponent and create similar mesh but only in the editor and outside play mode.. Put simply: I want to create gameobject equivalent of this entity...if that makes sense.

fallen berry
#

I figured out a workaround... since I am only ever accessing the bounds of the renderer, I will store that instead of the renderer. This seem to fix it!

#

Thanks @cursive dragon for leading me to this realization. I was losing my mind trying to figure out the cause of that error

cursive dragon
#

i've seen it a few time