Search Unity

EnableInClassList vs ToggleInClassList

Discussion in 'UI Toolkit' started by WizByteGames, Jun 27, 2019.

  1. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    I'm a bit curious as to which one should be used. Both methods sound as if they do the same thing from what I have read in the docs. Is there a reason You would use one over the other, or are they interchangeable?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    AddToClassList, RemoveFromClassList, EnableInClassList, and ToggleInClassList, all pretty much add or remove a string from...the class list. Nothing special about either one. So it's totally up to you. EnableInClassList() is nice if you already have a bool flag that you can give it, while Toggle() is for when you have full control of this element and are the only one controlling (toggling) the style on/off. But you can also just directly call Add/Remove.
     
    Zaddo likes this.