I was playing a while ago with the Editor API and the example shown on that page and it used to work, it was creating an additional button in the scene view.
I tried it again these days and it doesn’t seem to work.
I created a small user script to test that:
// ==UserScript==
// @name PC Editor Extension Test
// @namespace Violentmonkey Scripts
// @match https://playcanvas.com/editor/scene/*
// @grant none
// @version 1.0
// @author -
// @description 20/10/2021, 11:40:21
// ==/UserScript==
(function() {
function onLoad() {
console.log("Editor loaded.");
}
console.log("IT WORKS");
// Wait until the Editor is available before adding the button
editor.once("load", () => onLoad());
})();
and it only logs the IT WORKS message, the other console log is not shown which makes me believe that either the event is not registered or it is registered too late and the load event was already sent by the time we register for it inside the user script.
I’ve had a similar issue recently. I tracked it down to the editor load event listener: editor.once('load', () => createButton());
For some reason, the load event isn’t firing inside of the user script. Is it possible the recent editor changes are firing the load event earlier, before the event listener is added inside the user script?
My workaround is to simply call createButton() at the end of my userscript and not wait for the load event. Of course I still have to wait until the editor finishes loading before the button will work, but that’s no big deal.