sigtrapgames / SmartData

A designer-friendly, editor-driven Unity3D framework for connecting data and events.
MIT License
271 stars 14 forks source link

SmartRefUnbinder: Exception when connecting UnbindOnDestroy #14

Closed kaikuehne closed 5 years ago

kaikuehne commented 5 years ago

Hi again. Using master, I'm getting the same error as with the unity package described in issue #13. Firstly, if Auto Listening is enabled in the inspector, I'm getting a NullPointerException, because SmartRefUnbinder is trying to call GetField on a field that does not exist:

FieldInfo ownerGoId = typeof(SmartData.Abstract.SmartRefBase).GetField("_ownerGoId", BindingFlags.NonPublic | BindingFlags.Instance);

In SmartRefBase, the field is called ownerId, not ownerGoId. Changing the string fixes that bug.

Secondly, regarding the addition of multiple SmartRefUnbinder monobehaviour instances: The code in UnbindOnDestroy is just adding components, and is never checking if there already is a SmartRefUnbinder component existing on the related game object. Only adding the component if there is none fixes that error as well.

I can create a PR for this if you want. That would target master if that's fine. Honestly, I don't want to switch to dev if I don't have to. Speaking of that, there are no differences related to the changes I spoke about so the patch could be applied as-is on both branches.

sigtrapgames commented 5 years ago

Hi - I've now fixed this on master and dev, along with a bunch of other things. I'm planning to do a new release .unitypackage shortly as well.