Anim State Graph Closed Beta - Feedback here!

For any reason when I destroy an entity with a StateGraph, all other entities with the same state graph stop work. They return to T pose. The model, the animations and the state graph are assigned by code using the bitmoji library to create the assets. I have made sure that it is not destroyed by a event when I destroy the entity. The used classes are glb-converted-assets.js and utils.js

The code:

// Load model
 this.app.glbConvertedAssets.load(this.modelAsset, function (err, asset) {
        if (err){
            console.warn('Cannot load model asset: ' + err);
        }
        else {
            self.setModel(asset);
        }

MyClass.prototype.setModel = function(modelAsset)
{
    if(this.modelEntity.model.asset === null && modelAsset !== null)
    {
        this.modelEntity.model.asset = modelAsset.resource.model;

        var meshInstances = this.modelEntity.model.meshInstances;
        for (var i = 0; i < meshInstances.length; ++i) 
        { 
            var mesh = meshInstances[i];
            mesh.material = this.material.resource;
        }
    }
};

// Load animations

let numAnimationsLoaded = 0;

    for (var i = 0; i < this.stateAnimMappings.length; ++i) 
    {
        let mapping = this.stateAnimMappings[i]; // the animations
        if (mapping.animAsset) 
        {
            this.app.glbConvertedAssets.loadBitmoji(mapping.animAsset, function (err, asset) {
                if (err)
                {
                    console.error('Cannot load animation asset: ' + err);
                }

                numAnimationsLoaded += 1;
                if (numAnimationsLoaded == self.stateAnimMappings.length) 
                {
                    self.addAnimations();
                }
            });
        }



MyClass.prototype.addAnimations = function () 
{
    this.modelEntity.anim.loadStateGraph(this.animStateGraph.resource);
    var locomotionLayer = this.modelEntity.anim.baseLayer;

    for (var i = 0; i < this.stateAnimMappings.length; ++i) 
    {
        var mapping = this.stateAnimMappings[i];
        if (mapping.animAsset) 
        {
            var containerAsset = this.app.glbConvertedAssets.get(mapping.animAsset.id);
            if (containerAsset == null)
            {
                this._log.error('Animation ' + mapping.animAsset.name + ' not ready');
            }
            else
            {
                locomotionLayer.assignAnimation(mapping.stateName, containerAsset.resource.animations[0].resource);
            }
        }
    }
};

This code works fine, but for some reason when an entity is destroyed all those that share the state graph stop working. Any idea what the motive may be?

Try using https://developer.playcanvas.com/en/api/pc.AnimComponent.html#stateGraphAsset instead of

    this.modelEntity.anim.loadStateGraph(this.animStateGraph.resource);
1 Like

Works the same as loadStateGraph, thanks. But it doesn’t solve the problem.

further console.log(this.animGraph.baseLayer.activeState);
returns different states over time. The anim is working it seems. But not for the model.

image

Would it be possible to have a simple repro of this that @Elliott can investigate please :slight_smile:

I found a few bugs:

  1. Looping doesn’t save.

  2. you can right-click any state and the bar will stay there, same goes for transitions i think.

  3. Its possible to break the anim state asset by unlooping the first state

  4. Setting the speed to negative causes it to not play. Should play in reverse.

3 Likes

It’s possible to break the anim state graph asset to an unrecoverable state in which the editor refuses to open it so can’t fix the mistake.

Stack trace from the editor:

captureconsole.ts:73 TypeError: Cannot read property 'name' of undefined
    at pcui-graph.js:66
    at Array.forEach (<anonymous>)
    at pcui-graph.js:66
    at Array.forEach (<anonymous>)
    at new t (pcui-graph.js:66)
    at a.value (pcui-graph.js:66)
    at i.value (pcui-graph.js:66)
    at pcui-graph.js:66
    at Array.forEach (<anonymous>)
    at i.value (pcui-graph.js:66)
    at new i (pcui-graph.js:66)
    at AnimstategraphView._createGraph (editor.js:74127)
    at AnimstategraphView.link (editor.js:74268)
    at AnimstategraphAssetInspector.openFullscreenMode (editor.js:75994)
    at AnimstategraphAssetInspector.link (editor.js:76067)
    at editor.js:73335
    at Array.forEach (<anonymous>)
    at AssetInspector.link (editor.js:73322)
    at Editor.<anonymous> (editor.js:86046)
    at Editor.Events.emit (events.js:57)
    at Editor.<anonymous> (editor.js:56497)
    at Editor.Events.emit (events.js:57)
    at evtChangeFn (editor.js:24965)
    at sentryWrapped (helpers.ts:87)

Any situation where there’s a transition loop between 2 states without conditions causes this.
image

2 Likes

Another thing. I don’t know if this is a bug or maybe I’m doing something wrong (a more detailed documentation would really come in handy) but it seems like transitions can’t be interrupted? At least in this case:

I assumed that the construct below should always fire on the trigger but that isn’t the case.
ANY--[ Duration 0, interruption: Prev, Condition: trigger ]--[Attack]

The attack animation is delayed given enough triggers and I had to resort to this:

anim.setTrigger('Attack', true)
if (anim.baseLayer.transitioning)
    anim.baseLayer.play()

calling @Elliott

Thanks for reporting these issues. It looks like there was a bug when setting any state attributes which could affect looping / setting the speed / name. I’m currently testing a fix for this now so it should be updated shortly.

I’ve also updated context menus to disappear after 500ms of inactivity.

Thanks for sharing! Looking at the error this produces it seems to be related to the issue @Fus_ion raised. I’ll release a fix shortly.

1 Like

Which transition do you wish to interrupt the [ANY > Attack] transition with? As you’ve set the interruption source to ‘Prev’ it’ll only look for transitions coming from the ANY state which in this case means only the [ANY > Attack] transition can interrupt itself.

Note that the interruption source sets a transition to be interruptible rather than setting the transition as being able to interrupt other transitions.

Hi, I have same problem, If I make 2 states without conditions when I back from scene and try to open graph again nothing appens, the anim graph panel doesn’t appear!

are there any errors in the browser developed console?

here the screen when I click the button “open graph editor”:

Hi @dinof, thanks for reporting this. I wasn’t able to reproduce it with the steps you set out. Would it be possible to add me to the project that has the issue?

My PlayCanvas username is ellthompson

I understood! problem comes when you remove the flag from loop option at “initial state”
If I leave loop checked at “initial state”, problem doesn’t comes anymore. I can instead uncheck loop option for all other states without problems and witout errors in console.

I made a pubblic project: https://playcanvas.com/project/784703/overview/dino-bugtest--anim-graph-editor

1 - open: test scenes

2 - go to folder : anim graph editor

3 - you will find two graphs, only one can be opened (the one with loop checked at first state)

@redka @dinof @Fus_ion A fix has been released to production which should address the issues/crashes you were experiencing when editing state attributes in the graph editor.

4 Likes

Hello,

As I understood from “Tutorial Anim Blending” its impossible to prepare movements of entities through “Anim State Graph”, am I right?

What do you mean by ‘movements of entities’?

For example I want to prepare simple sliding door system which should be controled by a 2d button, so I need to prepare conditions of how sliding doors should open: speed of opening, length of movement of each door etc., so all this things I need to write in JS code which will be added to an entity in main editor of playcanvas, did I understand correctly?