Changing Texture with a Script


I’m currently trying to load the textures with a script, the problem is that when I use my script to load the textures, there are black borders that appear while in the editor no

I specify for my script I use the Zip version of the project

There is the model in PlayCanvas editor :

There is the model in Zip Version with my Script to load texture :

There is my script to load texture :

var LoadRecto = pc.createScript('loadRecto');
LoadRecto.attributes.add('loadingScreenEntity', {
    type: 'entity'

// initialize code called once per entity
LoadRecto.prototype.initialize = function () {, "texture", function (err, asset) {

        var recto = this.entity.render.meshInstances[1].material;

        recto.diffuseMap = asset.resource;



// update code called every frame
LoadRecto.prototype.getFileFromUser = function (dt) {

    id = 0;
    const queryString =;

    var url_string = window.location.href
    var url = new URL(url_string);
    var c = url.searchParams.get("token");
    var b = url.searchParams.get("startScene");

    url = `texture/${b}-${c}-recto-texture.png`;
    return url;
// swap method called for script hot-reloading
// inherit your script state here
// LoadRecto.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:

Maybe my script is bad ? i don’t know


Hi @Xora,

Check all the settings your texture asset has in editor, and try to set the same settings via code. For example if the UV address mode is different you can set it like this:

const texture = asset.resource;
texture.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
texture.addressV = pc.ADDRESS_CLAMP_TO_EDGE;

recto.diffuseMap = texture;
1 Like

Hi! i will try you’re method thanks!