Proper way to reference unity assets by path?
I am trying to reference an image like usual:
<BitmapImage x:Key="Images.Borders.Base" UriSource="/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg" />
The image appears under the XAML dependencies correctly, and it shows when the game is played in Unity, but I keep getting errors:
DirectoryNotFoundException: Could not find a part of the path "c:\Assets\Project\Features\Game\Features\Combat\Core\Media\T_Background.jpg".
I am also getting the same error in VS code: Image not found 'c:/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg'
How is it possible that the image is being found but is showing an error for a path that isn't correct?
<BitmapImage x:Key="Images.Borders.Base" UriSource="/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg" />
The image appears under the XAML dependencies correctly, and it shows when the game is played in Unity, but I keep getting errors:
DirectoryNotFoundException: Could not find a part of the path "c:\Assets\Project\Features\Game\Features\Combat\Core\Media\T_Background.jpg".
I am also getting the same error in VS code: Image not found 'c:/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg'
How is it possible that the image is being found but is showing an error for a path that isn't correct?
Re: Proper way to reference unity assets by path?
Are these errors coming from the language server used by VSCode?
Could you please close all VSCode instances and see if they keep happening?
Could you please close all VSCode instances and see if they keep happening?
Re: Proper way to reference unity assets by path?
It seems like the errors only appear when VSCode is open.
Re: Proper way to reference unity assets by path?
It looks like this could be an issue generating previews in the VS Code extension.
Could you please open a ticket and include a minimal project that reproduces the problem?
Thank you!
Could you please open a ticket and include a minimal project that reproduces the problem?
Thank you!
Re: Proper way to reference unity assets by path?
Based on the info in your post , I have not been able to reproduce getting DirectoryNotFoundException or Image not found errors in Unity, unless I put in an invalid path. Even then, with an invalid path, the path listed in the errors is full and correct.
Here's the XAML document I created in Unity in order to test, I matched the path of the image in Unity to the one you used.
Here's the XAML document I created in Unity in order to test, I matched the path of the image in Unity to the one you used.
Code: Select all
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
<BitmapImage x:Key="Images.Borders.Base" UriSource="/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg" />
<BitmapImage x:Key="Images.Borders.Comp" UriSource="/Assembly;component/Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg" />
<BitmapImage x:Key="Images.Borders.Invalid" UriSource="Assets/Project/Features/Game/Features/Combat/Core/Media/T_Background.jpg" />
</ResourceDictionary>
</Page.Resources>
<Grid>
<StackPanel>
<Border Height="200">
<Border.Background>
<ImageBrush ImageSource="{DynamicResource Images.Borders.Base}"/>
</Border.Background>
</Border>
<Border Height="200">
<Border.Background>
<ImageBrush ImageSource="{DynamicResource Images.Borders.Comp}"/>
</Border.Background>
</Border>
<Border Height="200">
<Border.Background>
<ImageBrush ImageSource="{DynamicResource Merged.Images.Borders.Base}"/>
</Border.Background>
</Border>
<Border Height="200">
<Border.Background>
<ImageBrush ImageSource="{DynamicResource Images.Borders.Invalid}"/>
</Border.Background>
</Border>
</StackPanel>
</Grid>
</Page>
Re: Proper way to reference unity assets by path?
We identified several issues related to this in version 3.2.10 and have since resolved them. This problem should no longer occur in the upcoming 3.2.11 release
Re: Proper way to reference unity assets by path?
Sorry for the late reply! Thanks for taking a look at this issue.
Who is online
Users browsing this forum: No registered users and 4 guests