Page 1 of 1

Xaml not found - unclear about how to preload XAML assets

Posted: 14 Jan 2025, 22:23
by KeldorKatarn
So I have a hard time understanding how to make sure that XAML assets are found.
In earlier documentation it was stated that some scene object needs to reference the asset. I've done that and that doesn't seem to do the trick.
Then I actively called xaml.Load(); on the asset that I have referenced in Start(). That works.

However now I have made my code a package, so the asset and the scene and the gameobject referencing it live in a package.

If I now import that package into a new project, open the scene and run it... it no longer works. I get "xaml not found", even though the same code works in the project where the package is created.

I'm confused on how to assure xamls are loadable at this point?

Re: Xaml not found - unclear about how to preload XAML assets

Posted: 15 Jan 2025, 00:05
by jsantos
Your scene should contain a game object (camera for example) with a NoesisView where your root XAML is set. The view will load the XAML for you. If you don't have a NoesisView for your XAML then you need to manually load the XAML doing xaml.Load();.

This is only for the root documents, dependencies (like UserControl or Dictionaries) are injected as dependencies (hard-references) and automatically loaded.

Re: Xaml not found - unclear about how to preload XAML assets

Posted: 15 Jan 2025, 03:31
by KeldorKatarn
Nevermind, just figured out there's a special way to include samples in a package. Noesis had no chance to find the path the way I was doing it.. sorry I'll fix that

Re: Xaml not found - unclear about how to preload XAML assets

Posted: 19 Jan 2025, 23:38
by BrandonReinhart
For future discoverers of this thread.

Internally, Noesis Unity keeps a Dictionary of some string (key) to a loaded xaml asset. By default that key is the path to the asset as if it were a static ref (ex: "Assets/Data/UI/MainMenu"). This code is in the NoesisXamlProvider.

If you want to load your asset using your own subsystem (for mods, async addressables, etc) you can register the asset after you've loaded it:
NoesisXamlProvider.instance.Register(my_key, noesisXaml);
And later, when you want to load a given component, you can use this key to associate the C# class with the correct xaml:
NoesisUnity.LoadComponent(this, my_key);
You will need to also register any images with the NoesisTextureProvider.

Those providers may overwrite your entries if you use disk paths like "Assets/UI/MainMenu" when they try to register static asset references, so use something else.

Re: Xaml not found - unclear about how to preload XAML assets

Posted: 24 Jan 2025, 21:19
by KeldorKatarn
For future discoverers of this thread.
[...]
Thanks, that's very useful