Referencing JSON from a JSON script attribute

I’m looking forward to have a json attribute inside another one…the only way I see fit if is to create a entity attribute inside a json schema and create a script for this entity to export its attributes as a json object… :sweat_smile:

I don’t like this workaround but its the only one i have since inside this second nested json must have references from entities and other kinds of info from my scene and i need the setup to be exposed to the editor to make things simple for non programmers in my team (if this wasn’t the case i could just link a json resouce from an asset attribute).

After binding the dependencyExported event on the parent script initialize function i was able to call the getDependency event on parent script postInitialize function

QuestManager.prototype.initialize = function () {

    let firstElement = this.info[0];
    firstElement.dependencies.on("dependencyExported", exportedJson => {
        this.info[0].dependencies = exportedJson;
        console.log(firstElement);

    });
};

This is the result:

1 Like

hummmm on second thought on ExportDependencyJson script i could have done this way i can get all necessary attributes without saying i need exactly the this.obj attribute

this.entity.fire("dependencyExported", this.__attributes)

1 Like

Is the Dependencies in info always going to be using a script of ExportDependencyJson?

I looked the code again and yeah :sweat_smile:…i did it there to test a point but now i notice i can’t reuse this code because it has fixed attributes xD

Well…now i don’t any workarounds for nested json attributes… :rofl:
i need this so badly…i guess i am too used to c++ struct syntax for my own good

What’s the end goal here?

I have interation options in my project to customize an apartment. Since i want to change both materials and meshes in scene (some objects require me to disappear other objects due compatibility issues and others requires i met a dependency check because some objects requires others visible before i can enable its entity). The json attribute is great because it is exposed to editor layout and my team can setup the options once i finish the script since they are not programmers…but since we have problems with nested json attribute i am stuck in my tasks looking a workaround for this limitation

What are you looking to nest? Is it always going to be the same schema of data or can it vary? In what ways can it vary and how?

For this project i think i can do something like this:

> script.attributes.add{"info", {
> type: "json",
> schema: [
>     {
>        name: info1,
>        type: string
>     },
>     {
>      name:info2,
>      type: string
>     },
>     { 
>        name: "dependency_itensToCheck",
>        type: "entity",
>        array:true
>     },
>    { 
>        name: "dependency_itensToDisappear",
>        type: "entity",
>        array:true
>   },
>   { 
>        name: "dependency_itensToAppear",
>        type: "entity",
>        array:true
>   }
> 
> ]
> }}

Its not ideal and its going to be messy to look it at editor panel but then i can select all the info i need from this “object” dependency. (i just tested and i can have attributes with “_” in their name, not sure if is a bug because it does’nt allow “-” or “.”)

Right now i just wanted to be able to mix different schemas into one json attribute

So dependency_itensToCheck, dependency_itensToDisappear, dependency_itensToAppear all have different JSON schemas/data to each other?

I don’t know how the editor works to parse this schema into a panel with exposed options but what i was thinking it could solve how to add more schemas into one json attribute is:

  1. Create an schemaRef:“path from file” assetType:“schema”
  2. Create an asset in assets panel from type JSON Schema

Then the system could load the asset from that path when you click “Parse” button and in theory you could place a schema under a existing json attribute

This is just a suggestion

the 3 of them are inside a single schema called “dependency” because in code i wish i could acess it by typing

this.info.dependency.itensToCheck
or
this.info.dependency.itensToDisappear

I was thinking of something like this setup: https://playcanvas.com/project/954416/overview/json-nested-workaround similar to your original attempt.

There are several variations of this that could make this more streamlined but I still don’t have a concrete idea of what you want workflow wise

This is a way to do it. Its not as convenient as a single json attribute with a schema that accepts other schemas though. For now its good to know i can “parse” my entities attributes into keys to build my json on runtime. Hope this limitation from Json Attributes gets solved soon.

Thanks you!

Unfortunately, it is unlikely to be done soon as it’s not on our immediate roadmap so I would look at solutions that don’t depend on this feature request being done in the near future