Can I change the visibility of attributes in the editor?

Basically i dont want some variables to appear in the editor.
If not, please can I request this :slight_smile:
eg…

MyScript.attributes.add("myVar",
{
    visible:"false",
    type: 'number',
    default:27
});

I read some requests for this a few years back which sort of morphed into a more
complicated request (hiding variables based on other variable values) which was then closed but I don’t think ever resolved. Im just wishing for the very basics here.

p.s I know i can just create something like this.myVar=27; manually in the init method but in some cases i would like to keep my attributes defined in the normal way at the top of the script.

Thanks

calling @Mark_Lundin
but I’d say the reason for attributes is to have them exposed in the inspector. If you don’t want them exposed, don’t use the attributes.

Hmm, agreed, but sometimes I might want to hide then temporarily or you may have a variable which is a chunk of quite complicated json schema or enums which takes time to recreate elsewhere. A ‘visible’ parameter would just make things so much easier.

There is an open issue:

Hey @Grimmy! With ESM Script we’re moving towards a new way of declaring attributes via jsdoc style comments. This means your example…

MyScript.attributes.add("myVar",
{
    visible:"false",
    type: 'number',
    default:27
});

in ESM Scripts will become this…

class MyScript extends Script {
   /** @attribute */
   myVar = 27
}

With this new format, you can simply remove the /** @attribute */ tag above the variable, and it will no longer be visible in the editor. You can read more about the proposal here.

It’s unlikely we’ll be making any further changes to the the older scripting/attribute system, although we will continue to support it. Hope that helps :smiley:

1 Like

I really meant something like:

if variable A = 0
…hide variable B in the editor
…else show variable B.

Stuff like that. I’m guessing its not possible but thought i would ask :slight_smile:

yep we’re very keen too, a proposal is here: [RFC] Conditional Script Attributes · Issue #1196 · playcanvas/editor · GitHub

1 Like

This isn’t possible at the moment, but a lot of people are asking, so we’ll definitley investigate.

Currently thinking something like this would work;

class MyScript extends Script {

   /** @attribute */
   a = 0; 

  /**
   * @attribute
   * @visibleWhen {a === 0}
   */
   b = 1; 
}

This tells the editor that b is only visible when a === 0. This obviously allows you to construct more complex conditions like only showing b when a is 0 and maybe when c is true.

If you think this might work for you, hit the :+1: on [RFC] Conditional Script Attributes · Issue #1196 · playcanvas/editor · GitHub as it will help us to gauge support.