Search Unity

Troubling binding manipulators outside the visualElement class

Discussion in 'UI Toolkit' started by Foxaphantsum, Apr 13, 2020.

  1. Foxaphantsum

    Foxaphantsum

    Joined:
    Jul 5, 2013
    Posts:
    139
    In my custom visual element class I have a manipulator like so

    Code (CSharp):
    1.     this.AddManipulator(_mouseHit2 = new MouseHitManipulator((() =>
    2.              {
    3.                  Debug.Log(_mouseHit2.IsMouseDown);
    4.              })));
    This works fine for both calling its callbacks and updating the manipulators public variables.


    However when I try to do a similar sorta binding outside the class as in

    Code (CSharp):
    1.        _previewUtil.AddManipulator(_mouseHit2 = new MouseHitManipulator((() =>
    2.             {
    3.                 Debug.Log(_mouseHit2.IsMouseDown);
    4.             })));

    The callbacks being called per event work fine but the manipulators public variables do not.

    I presume this has to do with why the class requires a this. before adding the AddManipulator


    Something about this I assume I'm lacking to understand, is there something I'm doing wrong and or a way around this?