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
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 = editor.call('selector:items');
if (swap.length === 2 && swap[0].get('type') === 'material' && swap[1].get('type') === 'material') {
swap = swap.map(function(i) {
return parseInt(i.get('id'), 10);
});
editor.call('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.
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?