How do I get the instance of an object attached in a plugin configuration?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi, everybody! 👋

    I'm developing a plugin for Construct 3 using SDK v2.

    This plugin requires you to select a Json object in its configuration.

    The code I wrote for this is:

    // plugin.js
    
    class BylothSDKPlugin extends SDK.IPluginBase
    {
     constructor()
     {
     super();
    
     // [...]
    
     SDK.Lang.PushContext(".properties");
    
     this._info.SetProperties([
     new SDK.PluginProperty("text", "endpoint-url"), // 0
     new SDK.PluginProperty("object", "datastore", { allowedPluginIds: ["Json"] }) // 1
     ]);
    
     SDK.Lang.PopContext(); // .properties
     SDK.Lang.PopContext();
     }
    }
    

    ... and:

    // c3runtime/instance.js
    
    class BylothSDKInstance extends globalThis.ISDKInstanceBase
    {
     constructor()
     {
     super();
    
     const properties = this._getInitProperties();
    
     this.endpoint = properties[0] as string; // "https://api.example.com"
     this.runtime.addEventListener("afterprojectstart", () =>
     {
     const objId = properties[1] as number;
     console.log("Object ID:", objId); // 565145407646531
    
     const datastore = this.runtime.getInstanceByUid(objId);
     console.log("Datastore:", datastore); // null
     });
     }
    }
    

    ... but no matter what kind of event I listen for or how long I wait before trying to get the instance, it always returns null.

    I also used setTimeout with 5s, 10s or 60s...

    I also tried listening for:

    • afteranylayoutstart which changes nothing.
    • afterload which isn't even called at all.

    I've exposed to the window the runtime instance and using the DevTools I'm actually able to explore and find all the objects.

    I've also verified that the ID was correct but getInstanceByUid will always returns null.

    Here's the proof:

    What am I doing wrong?

  • Oh, ok... Got it!

    getInstanceByUid - as the name itself - needs the actual the UID of the object.

    But - still - the original question is still valid: how do I get the instance of an object attached in a plugin configuration?

    In the SDK v1, it was possible by simply using the method GetObjectClassBySID...

    Using SDK v2 this method is no more available.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh, ok... Got it! (x2)

    The getObjectClassBySid method is now available on `runtime.sdk` as described here:

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/addon-sdk-interfaces/isdkutils

    My bad. 😅

    Solved.

    Thanks.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)