Adjusting to new NoesisGUI release for Unity
Posted: 25 Sep 2022, 08:57
I returned to my actual Unity project to make updates. It was running on one of the 2019 releases and I moved up to 2021. In the process, I updated NoesisGUI inside of it as well.
I have quite the pile of errors but I think it comes down to two categories:
1. Not resolving Xamls (again)
2. Constructor code getting run that previously didn't expect to run until game mode.
I went from Unity 2019.3.7f1 to 2021.3.10f1. Noesis is at 3.1.5. I can't find an easy way to see what I had beforehand. I think it was 3.0.8?
1. Not resolving Xamls (again)
Previously I had this:
Me using LoadComponent is an issue from a previous time and I guess it's now time to figure it out. Under my Unity project, the .xaml is indeed at Assets/Project/UI/wpf/mainmenu/MainWindow.xaml. The compiled asset is in Assets/Resources/UI/wpf/mainmenu/Top/MainWindow.asset; the convention for loading resources is to reference relative to the resource folder, not the root project folder. I never figured out why the Noesis.GUI.LoadComponent() call couldn't resolve the path. It lands in Noesis' own native code that I cannot step into so I don't know what its logic is for resolving these paths. Can somebody explain what I am actually supposed to feed it and how I could maybe get some diagnostics for the path resolution?
Going back to trying to use xaml.LoadComponent leads to a compilation error since that method is gone. I alternately found NoesisUnity.LoadComponent(this) to replace it, but that just causes Unity to crash hard.
I did see in the upgrade instructions that I shouldn't have to put compiled xamls in the resources folder. That's cool but I can't seem to get around it yet.
2. Constructor code getting run that previously didn't expect to run until game mode
Maybe the more fundamental problem are these build errors I get in my constructors off of my controllers. Stuff like this:
It looks like the Noesis package now actually tries to compile all that when processing assets. This is kind of a problem because some layers down, I am have some code that previously assumed it was happening in game mode that are just null references in the editor. That stuff shouldn't be running yet. Is this a goof on a poor assumption I made previously? Or did the convention on all this actually change? How do I keep that code for being run when the assets are getting initially loaded into the editor?
BTW, I do wonder if these problems are causes the assets to fail to load, so maybe fixing #2 fixes #1. I can hope.
I have quite the pile of errors but I think it comes down to two categories:
1. Not resolving Xamls (again)
2. Constructor code getting run that previously didn't expect to run until game mode.
I went from Unity 2019.3.7f1 to 2021.3.10f1. Noesis is at 3.1.5. I can't find an easy way to see what I had beforehand. I think it was 3.0.8?
1. Not resolving Xamls (again)
Previously I had this:
Code: Select all
private void InitializeComponent()
{
var xaml = UnityEngine.Resources.Load<NoesisXaml>("UI/wpf/mainmenu/MainWindow");
xaml.LoadComponent(this); // Compilation error
//Noesis.GUI.LoadComponent(this, "Assets/Project/UI/wpf/mainmenu/MainWindow.xaml");
}
Going back to trying to use xaml.LoadComponent leads to a compilation error since that method is gone. I alternately found NoesisUnity.LoadComponent(this) to replace it, but that just causes Unity to crash hard.
I did see in the upgrade instructions that I shouldn't have to put compiled xamls in the resources folder. That's cool but I can't seem to get around it yet.
2. Constructor code getting run that previously didn't expect to run until game mode
Maybe the more fundamental problem are these build errors I get in my constructors off of my controllers. Stuff like this:
Code: Select all
/// <summary>
/// Interaction logic for FullMainMenuNavigation.xaml
/// </summary>
public partial class FullGameMenuControl : UserControl
{
public GameMenuNavigationViewModel ViewModel;
public FullGameMenuControl()
{
#if NOESIS
ViewModel = new GameMenuNavigationViewModel();
this.DataContext = ViewModel;
#endif
InitializeComponent();
}
BTW, I do wonder if these problems are causes the assets to fail to load, so maybe fixing #2 fixes #1. I can hope.