Can't Overwrite Materials


I have some objects I need to overwrite in playcanvas, but I’m having a problem…
I spent hours working on the materials and I really need to overwrite the assets keeping the materials I have, but everytime I overwrite an asset, even if the material has the exact same name, playcanvas creates another material with diffuse color only.

I could change it one by one but I really have a lot of pieces, besides, it fills my projects with “copies” of the materials and not only increases the size of my project but also ruins my organization :dizzy_face:

Can anyone help me with this one?

  • This happens with any object on any project
  • This happens on any browser
  • Here’s an image of the mess :stuck_out_tongue:

Currently behaviour is this: when you upload we extract all materials. If there is any material with exact same name that was originally sourced from that the same model you are overriding, then it will replace that material from that model. In any other case it will create new material.
Unfortunately there is no control over that currently.

In the future there will be import settings that will allow you to set final result behaviour: use existing or update existing or create new.

I have made a small script for you that allows you to replace materials on all models in project from spcific ID with another material of specific ID.
Using it is pretty simple, open browser dev tools while in editor with console there.
Then select only two materials: first select material you want to replace, then hold ctrl/cmnd (win/mac), and select second material that will be set instead.
Then paste in console this script:

var swap ='selector:items');
if (swap.length === 2 && swap[0].get('type') === 'material' && swap[1].get('type') === 'material') {
    swap = {
        return parseInt(i.get('id'), 10);
    });'assets:list').forEach(function(asset) {
        if (asset.get('type') !== 'model') return;
        var mapping = asset.get('data.mapping');
        for(var i = 0; i < mapping.length; i++) {
            if (mapping[i].material === swap[0])
                asset.set('data.mapping.' + i + '.material', swap[1]);
} else {
    console.log('multi-select two materials, first one to be replaced with second one');

This will for all models in project replace first selected material with second one.

1 Like

As always, issue solved

Thank you very much once again

---- edit -----

Just a tip for anyone that’s in the same situation and will use this script:

If one or more of your objects turn white when you delete the other material just refresh the page and everything will be fine


any news on this? I have bunch of models all with the same three materials. They are all named the same, but I get a set of these for each model I upload. Is there a way to import models and make it assign material allready there if they share the same name to avoid duplicates? any Workaround?

Hi @bjorn.syse,

Yes, this was implemented, it’s not enabled by default:

I think that might only concern updading an existing model. What if 10 models shared the same material names, would they also not duplicate?

Mmm, yes I think so, each model will be treated to preserve the mappins, if it was uploaded at least once and you assigned materials.

But it’s easy enough to try, give it a go.