How can I get asset instance

Alex

Hello.
Problem: I can't receive instance ID after adding an asset to the player.

Code example:
async function getAssetInstanceId() {
const assetId = await api.scene.addNode(path, rootNode);

...

const instanceId = await api.player.getAssetInstance({

    from: getRootNode(api), // valid root node id

    id: assetId, // use my model assetId

    plug: ‘Null’,

    property: ‘asset’,

  }); // result - instanceId ==> null

}

Expected result: get valid asset instance ID

How can get it right?

Comments

5 comments

  • Comment author
    Marc Spencer

    Hi Alex,

    Can you try using 

    api.player.instanceId

    instead of

    api.player.getAssetInstance

    Let me know if this doesn't work and I will look into it further!

    0
  • Comment author
    Alex
    • Edited

    Marc Spencer

    api.player.instanceId did not help.

    Final result I want to get is to set some model properties window.api.scene.set. But instanceId is null and nothing is being set :


    const railMeshId = window.api.scene.findNode({
    from: instanceId,
    name: 'Item'
    });
    window.api.scene.set({
    id: railMeshId,
    plug: 'PolyMesh',
    properties: { type: 'Stretch' },
    property: 'stretchDistance'
    }, stretch);


    0
  • Comment author
    Marc Spencer

    Alex, 

    Did you try following the example in this article?

    https://community.threekit.com/hc/en-us/articles/4405866601243-Example-Custom-Script

    I have also relayed your question to the product team and will follow up with any further information.

     

    Thanks,

    Marc

    0
  • Comment author
    Marc Spencer

    Alex

    I don't think that the "from" field in your original post is necessary. You also need to make sure that your assetId is an actual node id. You can use this snippet as an example of how to get your node id.

    const nodeId = await playerApi.scene.addNode({ 
            type: 'Model',
            name: 'model', 
            plugs:{Null: [{type: "Model", asset:{assetId:'7da6f1f4-ca89-488a-b927-55b218c2c990'}}]}
        }, 
        playerApi.assetId);
    const instanceId = await playerApi.player.getAssetInstance({id:nodeId, plug:'Null', property:'asset'});

    If you make sure your assetId is the correct node id and remove the "from" parameter this should work as expected.

     

    Thanks,
    Marc

    0
  • Comment author
    Alex
    • Edited

    Solution.

    Problem: After migration from old "admin" environment to "preview" I was experiencing issues with getting instanceId.
    All instance ID's were null's.

    Solution: After reviewing with Threekit team issue was resolved by unchecking "Hidden Node Evaluation"(Settings -> Player Settings -> Hidden Node Evaluation -> uncheck the checkbox). Old "admin" player was operating synchronously, but the new preview/admin-fts works asynchronosly
     

    0

Please sign in to leave a comment.