AliciaCastillo
Topic Author
Posts: 16
Joined: 16 Apr 2024, 10:17

Custom components Package

20 Jun 2024, 17:05

Hi, is it possible to make a bunch of custom controls and pack them with noesis into a Unity package? i've been trying to do so and the package project itself works fine but when I include it into a sample project (a new empty project in Unity) it shows my custom controls but gives an error on Unity saying that can't find them in the given url but the files are there indeed
 
User avatar
sfernandez
Site Admin
Posts: 3112
Joined: 22 Dec 2011, 19:20

Re: Custom components Package

20 Jun 2024, 20:35

We haven't tested this scenario but the problem could be related to the path used by the UserControls when doing LoadComponent.
We exposed a helper function in NoesisUnity to automatically generate the path to the UserControl xaml, but it works only for controls placed inside Assets, not for external packages.
In your package controls you can just call GUI.LoadComponent with a path like this: "/Packages/com.your.package/Path/To/YourControl.xaml".

Could you try that?
 
AliciaCastillo
Topic Author
Posts: 16
Joined: 16 Apr 2024, 10:17

Re: Custom components Package

21 Jun 2024, 11:09

Hello, thanks for your answer,
That works fine for the controls inside the package and we are not getting anymore errors from them but the thing is that we still have the same error when trying to load the components inside a view in the sample project (the empty project for testing the external package). It's says that can't find the XAML for the custom component inside the package, have you any idea of how can we reference or load this file?
 
User avatar
jsantos
Site Admin
Posts: 4070
Joined: 20 Jan 2012, 17:18
Contact:

Re: Custom components Package

21 Jun 2024, 11:34

Hi Alicia,

Which path are you using to load that XAML from outside the package?

If it is in a package, as Sergio indicated, you need to use this format: "/Packages/com.your.package/Path/To/YourControl.xaml"
 
AliciaCastillo
Topic Author
Posts: 16
Joined: 16 Apr 2024, 10:17

Re: Custom components Package

21 Jun 2024, 12:15

Hi, i've got an example for you:

So we've got this control in our Sample project in Unity (Assets/SampleWindow.cs) :
 public partial class SampleWindow: UserControl
    {
        public SampleWindow()
        {
            this.InitializeComponent();
        }
#if NOESIS
        void InitializeComponent()
        {
            NoesisUnity.LoadComponent(this);
            GUI.LoadComponent(this, "/Packages/com.my.package/path/to/MyComponentsFolder/MyCustomComponent.xaml");
        }
#endif
    }
We are trying to load MyCustomComponent inside the SampleWindow but the error says that can't find the xaml file for MyCustomComponent

the definition for MyCustomComponent is this:
public partial class MyCustomComponent : UserControl
    {
        public MyCustomComponent()
        {
            InitializeComponent();
        }
    #if NOESIS

        private void InitializeComponent()
        {
            // NoesisUnity.LoadComponent(this);
            GUI.LoadComponent(this,  "/Packages/com.my.package/path/to/MyComponentsFolder/MyCustomComponent.xaml");
        }
    #endif
    }
At first, MyCustomComponent was giving the same error but this line fixed it
GUI.LoadComponent(this,  "/Packages/com.my.package/path/to/MyComponentsFolder/MyCustomComponent.xaml");
Now is in the SampleWindow trying to load MyCustomComponent where we are getting the error. Any ideas of what are we doing wrong or what can be not working?
Last edited by AliciaCastillo on 21 Jun 2024, 12:26, edited 1 time in total.
 
User avatar
jsantos
Site Admin
Posts: 4070
Joined: 20 Jan 2012, 17:18
Contact:

Re: Custom components Package

21 Jun 2024, 12:26

If I am understanding this correctly, SampleWindow should load its own XAML. And as it is not stored in any package, it should use standard Uris. Something like this:
public partial class SampleWindow: UserControl
    {
        public SampleWindow()
        {
            this.InitializeComponent();
        }
        void InitializeComponent()
        {
            NoesisUnity.LoadComponent(this);
        }
    }
 
AliciaCastillo
Topic Author
Posts: 16
Joined: 16 Apr 2024, 10:17

Re: Custom components Package

21 Jun 2024, 12:34

That is what I though but it's giving the error because the CustomComponent inside the SampleWindow is the one in the customPackage (path: /Packages/com.my.package/Path/To/MyCustomControls/MyCustomControl.xaml) :
<UserControl x:Class="Login.SampleWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
            [b] xmlns:components="clr-namespace:com.my.package;assembly=MY.CustomPackage"[/b]
             x:Name="Root"
             d:DesignWidth="1920"
             d:DesignHeight="1080"
             d:DataContext="{d:DesignInstance Type={x:Type local:ViewModel}, IsDesignTimeCreatable=True}"
             Foreground="#FF488EB5"
             Background="#FF4D5052"
             Focusable="True">
    <Grid>
        <StackPanel >
             <components:MyCustomComponent />
        </StackPanel>
    </Grid>
</UserControl>
 
User avatar
jsantos
Site Admin
Posts: 4070
Joined: 20 Jan 2012, 17:18
Contact:

Re: Custom components Package

21 Jun 2024, 14:04

Could you please paste the exact error you are getting including the stack trace?
 
AliciaCastillo
Topic Author
Posts: 16
Joined: 16 Apr 2024, 10:17

Re: Custom components Package

21 Jun 2024, 14:22

Sure, here is the error from the editor preview, LoginWindow is our SampleWindow and CommandsLegendPCBlock.xaml is MyCustomControl:
[NOESIS/E] Assets/Script/LoginWindow.xaml(43,13): Xaml not found '/Packages/com.bkool.bknoesiscomponents/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml'
UnityEngine.Debug:LogError (object,UnityEngine.Object)
NoesisUnity:UnityLog (int,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisUnity.cs:373)
Noesis.GUI:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:344)
BKOOL.UIComponents.Components.CommandsLegendPCBlock:InitializeComponent () (at /Users/fengel/Developer/unity/[email protected]/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml.cs:25)
BKOOL.UIComponents.Components.CommandsLegendPCBlock:.ctor () (at /Users/fengel/Developer/unity/[email protected]/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml.cs:16)
(wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure)
Noesis.Extend:CreateInstance (intptr,intptr) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/Extend.cs:5770)
Noesis.GUI:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:344)
NoesisUnity:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisUnity.cs:276)
Login.LoginWindow:InitializeComponent () (at Assets/Script/LoginWindow.xaml.cs:25)
Login.LoginWindow:.ctor () (at Assets/Script/LoginWindow.xaml.cs:20)
(wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure)
Noesis.Extend:CreateInstance (intptr,intptr) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/Extend.cs:5770)
Noesis.GUI:LoadXaml (System.IO.Stream,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:292)
NoesisXaml:Load () (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisXaml.cs:17)
NoesisXamlEditor:CreatePreviewView () (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Editor/NoesisXamlEditor.cs:29)
NoesisXamlEditor:HasPreviewGUI () (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Editor/NoesisXamlEditor.cs:216)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:203)
And here is it when we hit play:
[NOESIS/E] Assets/Script/LoginWindow.xaml(43,13): Xaml not found '/Packages/com.bkool.bknoesiscomponents/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml'
UnityEngine.Debug:LogError (object,UnityEngine.Object)
NoesisUnity:UnityLog (int,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisUnity.cs:373)
Noesis.GUI:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:344)
BKOOL.UIComponents.Components.CommandsLegendPCBlock:InitializeComponent () (at /Users/fengel/Developer/unity/[email protected]/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml.cs:25)
BKOOL.UIComponents.Components.CommandsLegendPCBlock:.ctor () (at /Users/fengel/Developer/unity/[email protected]/Runtime/Scripts/Components/CommandsLegendPCBlock.xaml.cs:16)
(wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure)
Noesis.Extend:CreateInstance (intptr,intptr) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/Extend.cs:5770)
Noesis.GUI:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:344)
NoesisUnity:LoadComponent (object,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisUnity.cs:276)
Login.LoginWindow:InitializeComponent () (at Assets/Script/LoginWindow.xaml.cs:25)
Login.LoginWindow:.ctor () (at Assets/Script/LoginWindow.xaml.cs:20)
(wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure)
Noesis.Extend:CreateInstance (intptr,intptr) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/Extend.cs:5770)
Noesis.GUI:LoadXaml (System.IO.Stream,string) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/API/Core/NoesisGUI.cs:292)
NoesisXaml:Load () (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisXaml.cs:17)
NoesisView:LoadXaml (bool) (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisView.cs:547)
NoesisView:OnEnable () (at /Users/fengel/Developer/unity/tests/noesis_tests/noesisLoginBinding/NoesisGUI-Unity-3-2/Runtime/NoesisView.cs:735)
 
User avatar
jsantos
Site Admin
Posts: 4070
Joined: 20 Jan 2012, 17:18
Contact:

Re: Custom components Package

24 Jun 2024, 17:57

Thank you for the error information.

It seems XAML dependencies are not properly calculated for User Controls stored in Unity packages.

Could you please create a ticket for this?

Who is online

Users browsing this forum: No registered users and 2 guests