Hi, I love the PlayCanvas Editor API, but I can’t help but wonder am I missing something in my code , even when I do a even a few print tests with it. Currently using the documented Editor API from here: https://github.com/playcanvas/editor-api/blob/master/docs/modules.md
90% I get undefined or null prints with no other console errors.
Questions
Should I be building locally with NPM?
If so do I really have to or can I perhaps use a CDN link somehow possibly?.
Should I be testing using the Violent Monkey extension only to allow partial embedding with my browser?
Currently I am testing by merely pasting my code from an external text-editor.
Do I have to call editor.call() for my code to work?
I tried with and without and I’m not getting much luck with either still. ^^
Currently I’m only using the documented Editor API like the API shown in the link above.
However, I was also wondering is there still some private API?
No. You don’t need the CDN either. The API is exposed on the Editor page.
I use Volient Monkey. I generally do small testing directly in the browser devtools console. To make things easier, I connect Visual Code to Violent (instructions on Violent Monkey site). You can create your own browser extension too.
No. Anything that is editor.call is ‘private’ API and subject to change. Some parts I’ve found are needed to get references to certain elements though.
Yes there is. On the Editor page, open up devtools and find the file editor.js. you can see the whole of the Editor code there.
How are you using the API? Directly in the console? If so, not all operations return a value hence undefined.
For example, assigning a value to a variable doesn’t return a value for the operation.
As a quick example: Select an entity in the hierarchy and type the following on the console:
editor.selection.item
That should print out the object selected in the console
So… I would need to create an extension even for testing? Or at least a function.
When I tried pasting in a function filled with code I got several line/indent syntax errors. Trying to find the correct way to code currently now.
Getting/setting entities properties works fine for me. But only if they’re selected. If I try to get an existing asset for example I always get either said undefined/null or even a unrelated list.
Earlier sort of yes. But currently no. (still working on building the basics of code before I write my extension)
Example of what I’m trying to do (probably doing it wrong):
Did you run the same code multiple times in the console in the same tab session? If so, some someAsset variable is in global scope and as its const, it can’t be reassigned to another value.
Change it from const to let
And when you next assign it a new value, no need to define it again. ie
It works somewhat now.
How would I change a dynamic asset though? Say I’m searching for all scripts and I check the names for some of them and need to reassign/update my variable placeholder list.
Edit:
Hm… My looping code doesn’t seem to be updating either
Both my attempts only get the last asset created.
Doesn’t matter really. The first one is modern JS and is considered ‘better’ as there’s less risk of getting something wrong. Eg forgetting to use the i value. Using the wrong index if its a nested set of loops. If the code in the loop was longer, you wouldn’t have to temp assign the asset you need.
TLDR whatever is understandable to you and gives you less code to maintain.