Variables appear then immediately disappear in editor

Hello,

I’ve created multiple scripts with variables on my project. No issues whatsoever until the “square” script. This script has variables in identical format to other scripts. This is the first new script where this issue happened.

When I add any NEW script (including square.js), then add that script to an entity’s script component, the variables appear for one frame, then are immediately hidden. I am not able to assign anything to these variables. Only new scripts suffer from this issue. If I copy an existing script and change the name, it also has this issue.

if I “REFRESH” the script, the variables will appear for one frame, then be hidden.

WTF?!??! Please help! :-]
project:https://playcanvas.com/editor/scene/1124650

thanks in advance
charlie

Hi @Charlie_Van_Norman and welcome,

Are you getting any errors shown in the lower left corner of your screen?

I’ve tried your project and both existing and new scripts with attributes seem to work fine.

Does it happen again if you reload your editor page?

I’ve forked the project and squareguy looks fine:

1 Like

The same issue just happend to me as well.

Copied the script from another project to work on it. The issue dosent appear in the other project.

var Carousel = pc.createScript('carousel');

Carousel.attributes.add('crossfade', {type: 'boolean', default: false});

Carousel.attributes.add('items', {
   type: 'json',
   schema: [
        {
            name: 'target',
            type: 'entity'
        },
        {
            name: 'fadeInSpeed',
            type: 'number',
            default: 150
        },
        {
           name: 'fadeOutSpeed',
           type: 'number',
           default: 150
        },
       {
           name: 'displayTime',
           type: 'number',
           default: 5500
       },
       {
           name: 'animate',
           type: 'boolean',
           default: false
       },
       {
           name: 'animStateGraph',
           type: 'asset',
           assetType: 'animstategraph'
       }
   ],
   array: true
});

// initialize code called once per entity
Carousel.prototype.initialize = function() {
    this.elapsedTime = 0;
    this.objectIndex = 0;
    this.itemActivated = false;
    
    console.log(this.items);
    
    if(this.items.length > 0) {
        this.item = this.items[this.objectIndex];
        this.ready = true;
    } else {
        this.ready = false;
    }
};

// update code called every frame
Carousel.prototype.update = function(dt) {
    if(!this.ready) return;
    
    if(!this.itemActivated)
        this.enableItem();
    
    this.elapsedTime += dt;
};

Carousel.prototype.enableItem = function()
{
    this.itemActivated = true;
    this.item.enabled = true;
    console.log(this.item);
};

was using the assetType: ‘animstategraph’, i guess that is not supported.

1 Like

@Elliott Is this something we can add?

@yaustar animstategraphs in script attributes?

@Elliott yea, i was trying to use it in the script attributes.

Thanks everyone for the swift replies! I did not discover the root of the issue, but eventually creating new scripts (SquareGuy) worked, even though I was doing the same thing as before. If it happens again I’ll try to get video of the issue via screen cap and post it here.