#[BUG] Calling GetComponents<Component>() in baker causes NRE

1 messages · Page 1 of 1 (latest)

raw stratus
#

There is not check on null for returned array, so it results in a throw

[Worker0] NullReferenceException: Object reference not set to an instance of an object
Unity.Entities.Baking.BakeDependencies+RecordedDependencies.DependOnGetComponents (System.Int32 gameObject, Unity.Entities.TypeIndex type, System.Collections.Generic.IEnumerable`1[T] returnedComponents, Unity.Entities.Baking.BakeDependencies+GetComponentDependencyType dependencyType) (at Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakeDependencies.cs:603)
Unity.Entities.IBaker.GetComponents[T] (UnityEngine.GameObject gameObject) (at Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/Baker.cs:215)
Unity.Entities.IBaker.GetComponents[T] () (at Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/Baker.cs:189)
#

@random kite

limber ingot
#

@raw stratus Thanks for the heads-up. Can you show the calling code that is causing this to fail so we can make sure we are fixing the correct issue?

raw stratus
limber ingot
#

Thanks! I logged a bug and we'll do our best to get to it ASAP.

tawdry vector
#

@raw stratus What is SomeMonoThatDidNotExist in your case? Is it a missing script for the component SomeMonoThatDidNotExist ? Or a missing component on the gameobject?

raw stratus
raw stratus
tawdry vector
#

ok thanks, and what version of Unity and entities package are you using?

raw stratus
#

that was 2022.3.3f and latest stable atm (1.0.14 if I'm not mistaken)

tawdry vector
#

I don't reproduce your issue. If the component is not attached to your gameobject, the enumerable passed to Unity.Entities.Baking.BakeDependencies+RecordedDependencies.DependOnGetComponents should be empty and not contain a null component. Where is located the script associated to the component? Somehow the Editor is not able to load the script in your case

raw stratus
#
        public T[] GetComponents<T>(GameObject gameObject) where T : Component
        {
            var components = gameObject.GetComponents<T>();

            _State.Dependencies->DependOnGetComponents(gameObject.GetInstanceID(), TypeManager.GetTypeIndex<T>(), components, BakeDependencies.GetComponentDependencyType.GetComponent);

            foreach (var component in components)
            {
                // Transform component takes an implicit dependency on the entire parent hierarchy
                // since transform.position and friends returns a value calculated from all parents
                var transform = component as Transform;
                if (transform != null)
                    _State.Dependencies->DependOnParentTransformHierarchy(transform);
            }
            return components;
        }
#

so basically if I remember correctly

#

components is null

#

it can return null in some cases