Search Unity

Tilmap: Detect when selected brush changes / "OnBrushDeselected"

Discussion in '2D' started by ShervinM, Sep 19, 2020.

  1. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    57
    Hi there!

    Pretty simple issue. I have a custom brush that forces the size and pivot of the brush to certain values. I want it so that when I'm using this custom brush and then I select another brush (usually the default brush) the size and pivot resets to Vector3.one and Vector3.zero respectively.

    Where is best to hook into for running code when a brush is deselected?

    Thanks!
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    915
    Do you have a custom editor for the brush, i.e. derived from GridBrushEditorBase? If so then perhaps the most natural place to put this hook would be OnToolActivated or OnToolDeactivated in the editor script. Reach into the brush and reset your size / pivot. I haven't used those hooks before so I can't guarantee they'll work for you, but if they're named well then that seems like it could work.
     
    ShervinM likes this.
  3. ShervinM

    ShervinM

    Joined:
    Sep 16, 2017
    Posts:
    57
    This did the trick! Should have looked more thoroughly at the API. Thanks a bunch!
     
unityunity