Page 1 of 1
Proper way to reference unity assets by path?
Posted: 09 Nov 2025, 04:36
by asusralis
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?
Re: Proper way to reference unity assets by path?
Posted: 11 Nov 2025, 19:53
by jsantos
Are these errors coming from the language server used by VSCode?
Could you please close all VSCode instances and see if they keep happening?
Re: Proper way to reference unity assets by path?
Posted: 13 Nov 2025, 04:24
by asusralis
It seems like the errors only appear when VSCode is open.
Re: Proper way to reference unity assets by path?
Posted: 18 Nov 2025, 19:26
by jsantos
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!
Re: Proper way to reference unity assets by path?
Posted: 01 Dec 2025, 18:59
by maherne
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.
<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?
Posted: 09 Dec 2025, 14:46
by jsantos
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?
Posted: 12 Dec 2025, 02:25
by asusralis
Sorry for the late reply! Thanks for taking a look at this issue.