Extenject icon indicating copy to clipboard operation
Extenject copied to clipboard

Change GetComponent to TryGetComponent or overload IsNotNull in editor for assert

Open Hlibix opened this issue 3 years ago • 0 comments

Copy of https://github.com/modesttree/Zenject/issues/255 by gonzanikolay!

Describe the bug Assert.IsNotNull (as well as IsNull) does not fall in editor, the problem is that GetComponent on Behaviour (not MonoBehavior) returns empty object, but not null.

To Reproduce Steps to reproduce the behavior: Add ZenjectStateMachineBehaviourAutoInjecter for example on empty game object and run in editor, there would be no errors, if you build on device, there would be Assert null error

Expected behavior Assert works in editor to prevent builds to fall with unknown reason

Screenshots If applicable, add screenshots to help explain your problem. https://imgur.com/SpeN9G6 - works in editor but fails on device

Extenject and Unity info (please complete the following information):

  • Zenject version: 8.0.0
  • Unity version: 2019.4.26
  • Project's scripting backend [e.g. Mono/IL2CPP] il2cpp

Additional context Add any other context about the problem here. We had a bit investigation and found out that GetComponent on Behaviour does not returns actual null, so we consider to change all GetComponent to TryGetComponent (for version 19.1) or overload null check for editor

Hlibix avatar Feb 19 '22 15:02 Hlibix