# LoadObject can't create a Texture2D from path (path is correct!)

**URL:** <https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415>\
**Category:** C++\
**Tags:** unreal-engine, question, CPP\
**Created:** [March 27, 2023, 12:49am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415 "2023-03-27T00:49:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![morphogen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morphogen](https://forums.unrealengine.com/u/morphogen)\
**Post date:** [March 27, 2023, 12:49am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/1 "2023-03-27T00:49:17Z")

</div>

I’m trying to create a `Texture2D` from a file path in my C++ file, and I’m receiving errors that it cannot do so.

The code:

```auto
        FString initialBackgroundPath =
            FPaths::ProjectContentDir() + "Core/screens/" + FString::FromInt(screenIndex) + "/main/background_0.png";
        UE_LOG(LogTemp, Log, TEXT("File path: %s"), *initialBackgroundPath);
        UTexture2D* initialBackgroundTexture = LoadObject<UTexture2D>(nullptr, *initialBackgroundPath);

```

This gives me the error:

```auto
LogUObjectGlobals: Warning: Failed to find object 'Texture2D None.D:/MyProject/Content/Core/screens/1/main/background_0.png'

```

I went ahead and checked in my File Explorer that this file exists, and the path is 100% correct – given that the path is correct, I’m actually kind of lost as to what else could be wrong here! It’s a pretty simple function call but the error is surprisingly mysteryious.

Any suggestions for what else could be wrong or how else to troubleshoot?

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [March 27, 2023, 12:56am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/2 "2023-03-27T00:56:48Z")

</div>

Hi scottnla1,

The LoadObject and FindObject are for loading “uasset” files, the native UE files.

Check out this thread about loading pngs:

> [@How can i load external images at runtime?](https://forums.unrealengine.com/t/how-can-i-load-external-images-at-runtime/316140):
>
> As the question says, can i dynamically load a PNG image, for example, and create a Texture2D from it? I’m trying to create an game launcher with covers and i need this for loading the cover images. See ya!

---

<div class="post-metadata">

**Author:** ![morphogen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morphogen](https://forums.unrealengine.com/u/morphogen)\
**Post date:** [March 27, 2023, 1:06am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/3 "2023-03-27T01:06:07Z")

</div>

How should I be using LoadObject if I have the correct uasset?

I actually tried creating a .uasset:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/0/7/507cafe2e3ad7237f50093958d9b4ec87fea2b26.png)

And changing the C++ code to reference the .uasset file instead:

```auto
        FString initialBackgroundPath =
            FPaths::ProjectContentDir() + "Core/screens/" + FString::FromInt(screenIndex) + "/main/T_background_0.uasset";
        UE_LOG(LogTemp, Log, TEXT("File path: %s"), *initialBackgroundPath);
        UTexture2D* initialBackgroundTexture = LoadObject<UTexture2D>(nullptr, *initialBackgroundPath);

```

But this gives me the same error:

```auto
LogUObjectGlobals: Warning: Failed to find object 'Texture2D None.D:/MyProject/Content/Core/screens/1/main/T_background_0.uasset'

```

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [March 27, 2023, 1:20am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/4 "2023-03-27T01:20:25Z")

</div>

You’re very close, just change the filename part to “T\_background\_0.T\_background\_0” - confusing I know, but the first one is for the “Package” (the uasset file) and the second one is for the asset contained in the package…

---

<div class="post-metadata">

**Author:** ![morphogen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morphogen](https://forums.unrealengine.com/u/morphogen)\
**Post date:** [March 27, 2023, 1:58am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/5 "2023-03-27T01:58:48Z")

</div>

I tried that and still get errors:

```auto
LogUObjectGlobals: Warning: LoadPackage can't find package Game/Core/screens/1/main/T_background_0.
LogUObjectGlobals: Warning: LoadPackage can't find package Game/Core/screens/1/main/T_background_0.
LogUObjectGlobals: Warning: Failed to find object 'Texture2D Game/Core/screens/1/main/T_background_0.T_background_0'

```

I created the assets by dragging and dropping them into the Content Drawer – could that be why maybe they aren’t structured properly?

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [March 27, 2023, 2:04am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/6 "2023-03-27T02:04:32Z")

</div>

Dragging them in should be ok as long as there’s no import errors.

You won’t need the “ProjectContentDir()” - replace that with “/Game/” and it should work.

---

<div class="post-metadata">

**Author:** ![morphogen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@morphogen](https://forums.unrealengine.com/u/morphogen)\
**Post date:** [March 27, 2023, 2:25am UTC](https://forums.unrealengine.com/t/loadobject-cant-create-a-texture2d-from-path-path-is-correct/826415/7 "2023-03-27T02:25:30Z")

</div>

That was it! Thank you so much!
