VUdon-Udonity icon indicating copy to clipboard operation
VUdon-Udonity copied to clipboard

Enable other scripts to reference the embedded UdonLogger (Console Window) script via the inspector

Open techanon opened this issue 1 year ago • 2 comments

I have support for the UdonLogger type in my asset SDK package, exposed generally as a inspector reference field. I would like to point that reference field at the ConsoleWindow reference that is included in Udonity's window structure so I can freely dump logs into there without having to do a special runtime search for it.

This is currently not possible because Udonity generates the entire structure at runtime (unless I missed something obvious).

I propose that the Udonity prefab be included with a GameObject containing the ConsoleWindow script exclusively. The references and hierarchy would be populated during runtime as normal, but it would allow inspectors to use it as an UdonLogger reference.

This consideration could be applied to any other scripts that are deemed valuable to expose as an inspector reference, but my main concern is the UdonLogger for debugging purposes.

techanon avatar Dec 13 '23 06:12 techanon

This is currently not possible because Udonity generates the entire structure at runtime (unless I missed something obvious).

Udonity's runtime UI is generated on build in two stages:

  1. Convert placeholder to runtime UI Order: -1000

  2. Postprocess Udonity Order: -100

I propose that the Udonity prefab be included with a GameObject containing the ConsoleWindow script exclusively. The references and hierarchy would be populated during runtime as normal, but it would allow inspectors to use it as an UdonLogger reference.

Unfortunately this will likely never be the case.

The UI is generated on build for two reasons:

  1. Error prevention, Udonity is extremely complex and having the full editor exist in edit mode makes it more prone to corrupted builds.

  2. Performance, due to Udonity's complex nature having the full editor exist in edit mode causes an excessive performance impact which can be prevented.

The current recommended method of accessing a reference to the ConsoleWindow/Logger is to access it from a build postprocessor, e.g.

        [PostProcessScene(-99)] // -99 or above
        private static void AccessUdonityReferences()
        {
            GameObject[] sceneRoots = SceneManager.GetActiveScene().GetRootGameObjects();

            Udonity udonityEditor = sceneRoots.Select(r => r.GetComponentInChildren<Udonity>(true)).FirstOrDefault(c => c != null);

            if (!udonityEditor) { return; }

            Varneon.VUdon.Udonity.Windows.ConsoleWindow consoleWindow = udonityEditor.ConsoleWindow;
        }

In the future a new component may get introduced for marking a field on an UdonBehaviour to be automatically populated by the Udonity build postprocessor.

Varneon avatar Dec 13 '23 12:12 Varneon

The UI is generated on build for two reasons:

My proposal is not to have the entirety of the full editor exist, only the ConsoleWindow script being supplementary. The hierarchy I would be expecting in editmode is:

  • UdonityEditor
    • LOGGER [ConsoleWindow script attached]

That's it. The change would be simply by where the game object exists (which even that can be re-parented if desired so long as the ConsoleWindow script reference is never deleted/destroyed).

The current recommended method of accessing a reference to the ConsoleWindow/Logger is to access it from a build postprocessor, e.g.

I'd also like to generally avoid adding other package dependencies when it'd simply just be a hack around trying to get the originally desired reference based on another package (in this case UdonLogger from VudonLogger package).

In the future a new component may get introduced for marking a field on an UdonBehaviour to be automatically populated by the Udonity build postprocessor.

While that's a nice idea, it still requires Udonity as a dependency instead of simply including the more abstract use of the VudonLogger package.

techanon avatar Dec 13 '23 12:12 techanon