asusralis
Topic Author
Posts: 152
Joined: 30 Jul 2018, 05:03

Proper way to reference unity assets by path?

09 Nov 2025, 04:36

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?
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Proper way to reference unity assets by path?

11 Nov 2025, 19:53

Are these errors coming from the language server used by VSCode?

Could you please close all VSCode instances and see if they keep happening?
 
asusralis
Topic Author
Posts: 152
Joined: 30 Jul 2018, 05:03

Re: Proper way to reference unity assets by path?

13 Nov 2025, 04:24

It seems like the errors only appear when VSCode is open.
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Proper way to reference unity assets by path?

18 Nov 2025, 19:26

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!
 
User avatar
maherne
Site Admin
Posts: 53
Joined: 01 Jul 2022, 10:10

Re: Proper way to reference unity assets by path?

01 Dec 2025, 18:59

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>
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Proper way to reference unity assets by path?

09 Dec 2025, 14:46

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
 
asusralis
Topic Author
Posts: 152
Joined: 30 Jul 2018, 05:03

Re: Proper way to reference unity assets by path?

12 Dec 2025, 02:25

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