Setting colors from an attribute

Hi, I have a color attribute:

MyScript.attributes.add('theme_default_color', {
    type: 'rgb',
    default: [1, 0, 0] 
});

…and then in my script i want to set an object based on this color , but it doesnt work :frowning:

Setting it manually like this works fine:

material.emissive.set(1, 0, 0);

but doing this doesnt work…

material.emissive.set(this.theme_default_color);

The color gets set to black.
Any ideas?

p.s.I also tried
material.emissive.set(this.theme_default_color.r,this.theme_default_color.g,this.theme_default_color.b);

additionally this doesnt work either:
material.emissive.set(new pc.Color(this.theme_default_color));

…but I still got black.
Cheers

Hi @Grimmy , default colour in playcanvas is rgba. While your attribute is rgb. Try changing your attribute to rgba

Thanks but sadly that doesnt work either :frowning:

Can you reproduce in an empty project?

I figured it out. Thanks!
As usual, I hadnt put a ‘bind’ in to access the .this so my theme_default_color was becoming null. This was the root of all the issues. In fact it’s almost always the root of all my issues :slight_smile:

Glad you found that

1 Like