[SOLVED] Why can't set the attributes that defined at the script

Hi,I’ve create a button by the code downside:

var Button = pc.createScript('button');

Button.attributes.add("bgType",{
    name:"bgType",
    type:"number",
    default:0,
    enum:[
        {'image':0},
        {'color':1}
    ]
});

Button.attributes.add("hoverAsset",{
    type:"asset",
    assetType:"texture",
});

Button.attributes.add("hoverAssetRect",{
    type:"vec4",
    default:[0,0,1,1],
    placeholder:["u","v","w","h"]
});
Button.attributes.add("hoverColor",{
    type:"rgb",
    default:new pc.Color(0,1,0)
});

Button.attributes.add("checkedAsset",{
    type:"asset",
    assetType:"texture"
});
Button.attributes.add("checkedAssetRect",{
    type:"vec4",
    default:[0,0,1,1],
    placeholder:["u","v","w","h"]
});
Button.attributes.add("checkedColor",{
    type:"rgb",
    default:new pc.Color(1,0,0)
});

Button.attributes.add("disableAsset",{
    type:"asset",
    assetType:"texture"
});
Button.attributes.add("disableAssetRect",{
    type:"vec4",
    default:[0,0,1,1],
    placeholder:["u","v","w","h"]
});
Button.attributes.add("disableColor",{
    type:"rgb",
    default:new pc.Color(0.5,0.5,0.5)
});

But when I try to set the hoverColor or CheckedColor etc. The editor throw the error like this:

Try changing the default value of your color attributes to arrays, e.g. instead of new p.Color(0.5, 0.5, 0.5) try passing [0.5, 0.5, 0.5] instead.

That seems doesn’t work. The error still exist

Did you reparse the script in the Editor after changing the default attributes?

Yes, I’m sure I’ve reparsed the script. And the script was changed into:

And the editor looks like this:

It seems like the default value doesn’t work.

Can you share a link to your project?

https://playcanvas.com/editor/scene/551244

Can you try refreshing your editor? It seems to work for me.

It seems works to me too. Thank you

1 Like

It seems like the parse button dosen’t work for me. I changed the script and click the parse button, but it can’t work. I have to delete the script and readd it

Do you have any errors / warnings in your browser console?

That should be fine. How exactly are you changing the script and it doesn’t work?

Can you create a simple reproducible case I can look into? Like a blank project with 1 script where after you change the script and reparse doesn’t change the Editor.

I know what it is. You need to delete the script you already attached and put it back on now you have the color default set properly. It’s remembering the dodgy one from earlier. Which is why the color is still showing black and not green.

https://playcanvas.com/editor/scene/551244
Well, It seems work too. I am sorry for taking your time

Yes, thank you:slight_smile:

Don’t sweat it :slight_smile: The number of times I’ve done exactly that with colors :slight_smile: