[SOLVED] Change material at runtime

I’m dipping into the coding aspect of PlayCanvas and I’m not a strict fan of JS / HTML. So I do struggle a little with the convention. I used to program in AS3, but those days are gone :frowning:

Anyways, I’ve searched and searched and I’ve found scripts to alter the diffuseMap of a material, but I really would like to swap Materials in one hit. I’ve got 2 materials so far, they consist of diffuse, normal, occlusion, roughness and specular.

The normal maps do change per material.

I can see I can get to certain parameters such as diffuseMap, but I want to alter the upper level, but cannot fathom it out at all. Any ideas?

Should I reference shader rather than material?

cheers

Scott

Hi @pixelised and welcome!

I’m not exactly sure what you are looking for, but maybe the page below can help.

https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/

1 Like

Hi Albertos,

Thanks for the link. I discovered the other version of this scene, where only the diffuseMap was altered. I’ve just had a quick look at the code and it looks like that’s the one. I will try tomorrow and report back.

Many thanks for the ultra swift reply :smiley:

2 Likes

Morning Albertos,

Thanks for that, that is exactly what I’m after. Means I can move onto the next steps now.

Thanks again

Scott

1 Like

Hey man, I miss Flash games and ecosystem too, there will never be one like it, ever again :sob:
all game dev tooling that was released since flash, is a pain in the butt for casual 2d games, those days were fun :v:

Agreed, I’m not keen on developing anymore as a result of the nail in the coffin for Flash, everything is far too fragmented for my liking, a library for this, for that etc… Mind, I don’t mind BluePrints in UE.

I used to write simulations in Flash, a partial cockpit simulation that could be packaged up into a few Mb file and fully scalable. I think unity used Flash as the UI layer at one point, those days are gone too.