Unity Custom Editor: 1 True Bool Only Within A Group

Hi,

In custom inspector what’s the best way to deal with setting only 1 bool to true and everything else to false? So in other words, i only want 1 bool to be able to be true and if that 1 bool is true then all the other bools are set to false.

i recall seeing something like being able to group our bools together in the custom inspector and easily performing this function but i can no longer find it. The other alternative would be something like using an if statement and within the if setting everything else to false but i feel like there’s a more elegant way of doing it for a custom inspector.

Any help will be appreciated!

hm if you have a list of bools where only one bool can be true at a time, why don’t you use an int switch?

int casehandler = 0;

switch(casehandler){
  case 0:
  //do something
  break;
  case 1: 
  //do something
  break;
  case 2:
  //do something
  break;
  
  //and so on
}

but to answer your question with this you can call a bool in an array to set true/false(default true), and the rest to the opposite of what you choose. boolhandler(boolarray,index of which bool you want to change, true/false);

bool[] boolhandler(bool[] b,int index, bool setTo = true){
  for(int i = 0; i<b.Length;i++){
    if(i == index){
      b *= setTo;*

}
else{
b = !setTo;
}
}
return b;
}

//example
bool[] myboolarray = referencearray;

myboolarray = boolhandler(myboolarray, 2, true);