KeldorKatarn
Topic Author
Posts: 243
Joined: 30 May 2014, 10:26

Xaml not found - unclear about how to preload XAML assets

14 Jan 2025, 22:23

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?
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

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

15 Jan 2025, 00:05

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.
 
KeldorKatarn
Topic Author
Posts: 243
Joined: 30 May 2014, 10:26

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

15 Jan 2025, 03:31

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
 
BrandonReinhart
Posts: 29
Joined: 10 Jan 2025, 17:02

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

19 Jan 2025, 23:38

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.
 
KeldorKatarn
Topic Author
Posts: 243
Joined: 30 May 2014, 10:26

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

24 Jan 2025, 21:19

For future discoverers of this thread.
[...]
Thanks, that's very useful

Who is online

Users browsing this forum: jinfox and 2 guests