TylerTemp/SaintsField

UnassignedReferenceException with null-conditional

laurentopia opened this issue · 3 comments

Something I've never seen before:
rigidBody?.AddForceAtPosition(direction, hitPoint, ForceMode.Impulse);
causes that:
UnassignedReferenceException: The variable rigidBody of MCUnit has not been assigned.

and that's how rigidbody is set, automatically:
image

so either I never paid attention to that error before or GetComponent does something strange, other than nulling a field

Hi,

this possible happens when things are correct in edit mode, and then when go to play mode, you manually active the object, and because in playing mode the logic is a bit different, this decorator might fail to get the component, and decide to null the field. (But not sure it's because of this)

I'll disable the GetComponent* ability in play mode in next release

I understand, it's probably better to do that so that it matches the behavior of a build.