- AliciaCastillo
- Posts: 16
- Joined:
Custom components Package
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
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Custom components Package
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?
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
- Posts: 16
- Joined:
Re: Custom components Package
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?
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?
Re: Custom components Package
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"
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
- Posts: 16
- Joined:
Re: Custom components Package
Hi, i've got an example for you:
So we've got this control in our Sample project in Unity (Assets/SampleWindow.cs) :
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:
At first, MyCustomComponent was giving the same error but this line fixed it
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?
So we've got this control in our Sample project in Unity (Assets/SampleWindow.cs) :
Code: Select all
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
}
the definition for MyCustomComponent is this:
Code: Select all
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
}
Code: Select all
GUI.LoadComponent(this, "/Packages/com.my.package/path/to/MyComponentsFolder/MyCustomComponent.xaml");
Last edited by AliciaCastillo on 21 Jun 2024, 12:26, edited 1 time in total.
Re: Custom components Package
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:
Code: Select all
public partial class SampleWindow: UserControl
{
public SampleWindow()
{
this.InitializeComponent();
}
void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
}
- AliciaCastillo
- Posts: 16
- Joined:
Re: Custom components Package
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) :
Code: Select all
<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>
Re: Custom components Package
Could you please paste the exact error you are getting including the stack trace?
- AliciaCastillo
- Posts: 16
- Joined:
Re: Custom components Package
Sure, here is the error from the editor preview, LoginWindow is our SampleWindow and CommandsLegendPCBlock.xaml is MyCustomControl:
And here is it when we hit play:
Code: Select all
[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)
Code: Select all
[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)
Re: Custom components Package
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?
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: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests