tylerwsavatronix
Topic Author
Posts: 13
Joined: 07 Mar 2017, 11:45

Unity advanced use: Loading all UI at runtime from external source

21 Feb 2023, 00:34

Hi there,

We have a fairly advanced use case where, to enable robust mod support we're building our game using as close to the same process as we envision modders will also use (highly modular design, loading and converting assets at runtime from external locations, etc... etc...). The way we're planning for this is to not have any of these dynamic assets be directly assets in Unity itself, but probably streaming assets for our build (and subfolders in a /mods directory for modders).

Modders (and by extension us) should be able to modify existing UI via XAML manipulation (adding, editing, etc..) and/or add entirely new UI elements and their own custom user controls using blend or any other text editor, without having to use Unity itself in any way.

Modifying XML/XAML in memory before loading it is itself not a problem, generally speaking (there's a few different standards for manipulating XML based stuff in memory and then loading that). I have read here on the forums that things like dependencies won't work this way (using LoadXAML/ParseXAML) and am not sure if that's still the case, and if it is how that could be resolved.

My questions are,
Is this possible with Noesis?
If so what is the best way to go about reaching this goal using Noesis?
If dependencies can't be resolved automatically, is there some way to do this manually?

-----
Supplemental Info

It might make more sense if I give a use case for kind of how we expect to be able to do these things.

Modifying existing:
The user would create a diff XML file following https://www.rfc-editor.org/rfc/rfc5261, at runtime our app would load the original in memory (probably via System.XML) and then iterate through all mod folders, patching the XML/XAML as needed and then load that result as the final UI XAML. The existing might be our MainView.XAML of any of the user controls we're creating.

Creating New:
User would use blend or whatever other tools they desire to create their custom user controls, along with creating and compiling an assembly for the accompanying code (to be loaded at runtime by us). They would diff in (see above) their user control so that it appears where they want it (for example, appending their new user control to the end of a list view or whatever to have their new menu button appear in game).
 
User avatar
jsantos
Site Admin
Posts: 3694
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity advanced use: Loading all UI at runtime from external source

23 Feb 2023, 12:36

Modding is supported in NoesisGUI in a very natural way and there are many games already exposing it (for example this mod for BG3).

Right now in Unity, you can load XAMLs from memory using ParseXaml but if this XAML is using resources (images, fonts) we won't find them if they are not in your project (and imported by Unity).

But we could implement callbacks in our resource providers, just in case we can't find the resource you can load it manually (for example using UnityWebRequestTexture).

Please, let me know how this sounds to you.
 
tylerwsavatronix
Topic Author
Posts: 13
Joined: 07 Mar 2017, 11:45

Re: Unity advanced use: Loading all UI at runtime from external source

24 Feb 2023, 10:35

Modding is supported in NoesisGUI in a very natural way and there are many games already exposing it (for example this mod for BG3).

Right now in Unity, you can load XAMLs from memory using ParseXaml but if this XAML is using resources (images, fonts) we won't find them if they are not in your project (and imported by Unity).

But we could implement callbacks in our resource providers, just in case we can't find the resource you can load it manually (for example using UnityWebRequestTexture).

Please, let me know how this sounds to you.
Yeah, a callback would probably be a good way to handle it. Since we'll probably be storing loaded assets like those in an in memory DB, our handler would just need to, in theory, find it in there and return it.

Should I do up a ticket in the bugtracker?
 
User avatar
jsantos
Site Admin
Posts: 3694
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity advanced use: Loading all UI at runtime from external source

01 Mar 2023, 10:40

Yes, please, file a ticket about this. Thank you!
 
tylerwsavatronix
Topic Author
Posts: 13
Joined: 07 Mar 2017, 11:45

Re: Unity advanced use: Loading all UI at runtime from external source

12 Mar 2023, 12:36

Yes, please, file a ticket about this. Thank you!
Apologies for the delay, it's been a hectic couple of weeks.

The issue's been posted.

As a side note, is a possible current workaround to bind to a property on the viewmodel (e.g. Texture2d MyImage on the viewmodel) that we'd set on the viewmodel at runtime instead of using resources and might that actually be a better solution for dynamic content?
 
User avatar
sfernandez
Site Admin
Posts: 2794
Joined: 22 Dec 2011, 19:20

Re: Unity advanced use: Loading all UI at runtime from external source

27 Mar 2023, 12:50

As a side note, is a possible current workaround to bind to a property on the viewmodel (e.g. Texture2d MyImage on the viewmodel) that we'd set on the viewmodel at runtime instead of using resources and might that actually be a better solution for dynamic content?
Yes, you can bind to Texture2D properties exposed in the ViewModel without problems. But I don't see how you plan to use it for dynamic content... would it be something like binding to a dictionary in your view model with the new textures?
 
tylerwsavatronix
Topic Author
Posts: 13
Joined: 07 Mar 2017, 11:45

Re: Unity advanced use: Loading all UI at runtime from external source

28 Mar 2023, 09:58

Yes, you can bind to Texture2D properties exposed in the ViewModel without problems. But I don't see how you plan to use it for dynamic content... would it be something like binding to a dictionary in your view model with the new textures?
Depends on what the image is. If it's, say, static UI (part of the hud or a menu, whatever) it'd be a single texture2d property. Like, say, a heart icon serving as a label to a health bar.

For list-based content (like an inventory) it would probably have to be a list of items that include the texture2d as a property on the specific item data.

The specific asset to use would be determined when loading the game as part of the mod-loading system. e.g. if a mod wants to replace the above mentioned heart icon, they'd just provide their own and when the game is loading it would load that instead of ours (probably via in mem database). We'd then inject that either via constructor or property injection to wherever needed.
 
User avatar
sfernandez
Site Admin
Posts: 2794
Joined: 22 Dec 2011, 19:20

Re: Unity advanced use: Loading all UI at runtime from external source

28 Mar 2023, 11:21

The specific asset to use would be determined when loading the game as part of the mod-loading system. e.g. if a mod wants to replace the above mentioned heart icon, they'd just provide their own and when the game is loading it would load that instead of ours (probably via in mem database). We'd then inject that either via constructor or property injection to wherever needed.
Understood, that makes sense then. I think that could be a good approach for allowing custom textures in mods.

Who is online

Users browsing this forum: Bing [Bot] and 8 guests