[SOLVED] Script Attributes - boolean overwriting value on parse

I’m seeing some weird behaviour in the editor under some very specific circumstances:

  1. Have a script with a json style attribute
  2. Have a boolean sub attribute with default: true
  3. Have a second sub attribute with an enum
  4. Parse the script and note the boolean value is overwritten as true <— unexpected, should retain value from before script parse

See the most minimal version example below.


  • Using latest Chrome under Windows
  • No messages in the dev tools console (errors or otherwise)
var TestBoolDefaultReset = pc.createScript('testBoolDefaultReset');

TestBoolDefaultReset.attributes.add('editorBug', {
    type: 'json', // <--- the bug seems related to this (not using json makes the bug go away)
    schema: [{
        name: 'someEnum',
        type: 'string',
        enum: [{'defaultVal': 'defaultVal'}], // <--- the bug seems related to this (removing it makes the bug go away)
        default: 'defaultVal'
    }, {
        name: 'someBool',
        type: 'boolean',
        default: true // <--- this overwrites the editor value when the script is parsed
1 Like

It feels like a step or observation is missing? It’s mentioned that something is overwritten but not what was set or the state of the attribute before the script is parsed?

The bool is overwritten.

Whichever state the bool was in (true or false)… parsing the script makes the bool true.

I think this is as designed. If the value of an attribute is at it’s default value. eg

Test.attributes.add('foo', {type: 'number', default: 10});

And in the editor:

It is deemed to be in it’s default state so changing the default value in the scripts attribute would also change it in the Editor when parsed.

At the moment, there’s no concept of a value in the Editor being ‘written to’ if it’s at the same value.

I will put a request into the repo about this as it’s an interesting issue :thinking:

I really appreciate you looking at this yaustar, but I don’t think I’m being clear enough about the issue.

I’m saying that some values assigned to script attributes in the editor… are changing (without the script source changing) when the parse button is pressed.

If you create the script that I posted above, then attach the script to an entity and parse the script:
Then try setting the bool to an off state.

Everything should be normal at this stage.

But… when you press the parse button, the bool value changes to true. Parsing the script is changing a value that was previously set in the editor. With the script changing at all.

Yeah, the issue here in your case that when the default is false in the script attributes, you only have two options in the Editor:

false: default value
true: user set value

There’s currently no concept of:
false: user set value

So when the default in the script is changed to true, when parsing again in the Editor, it would set the value in the Editor to true because it was deemed to be in it’s default state.

If this isn’t the issue, can you create a video of the issue please?

Edit: Oh wait, I think I know what you mean. Two secs

I see it now, yep that’s definitely a bug

1 Like

That’s it! Thanks yaustar.

Bug reported: JSON attributes will set to default in Editor when parsed despite no code changes · Issue #468 · playcanvas/editor · GitHub

1 Like

A fix for this was deployed today. Let us know if you encounter any further problems though.