Creating Entities Dynamically in the Editor and Synching in Hierarchy

So I have a bunch of UI popups with text that I am instantiating dynamically at runtime via JSON. However, I would love to be able to generate them in the editor, without having to manually create each one so that I could edit a few of them that didn’t layout correctly.

I have successfully used @Leonidas Uranus Editor to run my script in the editor, and I can see the popups in the scene view, however the UI Element Group that is a parent to the popups is not updating in the hierarchy to show these new children. If I turn the element group off the popups turn off, if I add a Layout Group the popups will space out correctly, I just cannot get them to show in the hierarchy.

The issue seems to be that I am not instantiating the popups via the editor itself so I have been trying (very unsuccessfully) using the JavaScript Console and editor.call commands to clone my Element Group, copy paste an instance of the element group, synchInHierarchy the element group. But I am just stuck at this point.

Hoping someone can help me out!
Thanks so much,
Justin

Hi @justinISO,

Official support for editor scripting is currently being worked on, here is a sneak peek:

You can still use the existing unofficial editor API that you can review by studying the un-minified editor.js code, here is the link:

https://playcanvas.com/editor/scene/js/editor.js

Note that API will change and most likely a lot when the official API is released.

To your question I don’t think there is an event based method that you can call to clone an entity (I may be wrong though, maybe @vaios can share some light). There is a local method that is called internally when you duplicate an entity:

I don’t think you can call that externally though, so the only way would be to study and create your own version of it. Be extra careful, definitely create a checkpoint ahead of time.

Good luck!

1 Like