# LoadObject without hardcoding the file path

**URL:** <https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [November 29, 2019, 6:52am UTC](https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195 "2019-11-29T06:52:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bitwaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bitwaker](https://forums.unrealengine.com/u/Bitwaker)\
**Post date:** [November 29, 2019, 6:52am UTC](https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195/1 "2019-11-29T06:52:17Z")

</div>

Hello, I’m struggling to find a way to pass a TCHAR with the path of the file to LoadObject. All the examples that I’ve seen are passing a fixed path like:

```auto

 LoadObject<UParticleSystem>(NULL, TEXT("A/PATH/TO/A/FILE"), NULL, LOAD_None, NULL);

```

what I’m trying to do is receiving the path from another object instead, something like:

```auto

 LoadObject<UParticleSystem>(NULL, AnoherObject->ThePath, NULL, LOAD_None, NULL);

```

## I’ve tried 2 ways since now (and both failed):

\*\*1) \*_create “ThePath” variable as a TCHAR_ public variable for AnotherObject

```auto

public:
    TCHAR* ThePath = TEXT("A/PATH/TO/A/FILE");

```

## it crashes the engine…

\*\*2) \*\*Use an FString as value for the “ThePath” variable and use the \* to get a TCHAR

```auto

public:
    Fstring ThePath = "A/PATH/TO/A/FILE";

```

```auto

 LoadObject<UParticleSystem>(NULL, *AnoherObject->ThePath, NULL, LOAD_None, NULL);

```

## it crashes the engine…

Which is the right way to pass the path to LoadObject without hardcoding the path in the call?!

---

<div class="post-metadata">

**Author:** ![Bitwaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bitwaker](https://forums.unrealengine.com/u/Bitwaker)\
**Post date:** [November 29, 2019, 7:07am UTC](https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195/2 "2019-11-29T07:07:55Z")

</div>

It seems that option 2 is actually working correctly. I keep this question open since I wasn’t able to find the right way to load assets without hardcoding the file path.

Please provide anyway feedback if you see any issue with this approach to assets loading.

---

<div class="post-metadata">

**Author:** ![Waves](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/waves/32/1009258_2.png) [@Waves](https://forums.unrealengine.com/u/Waves)\
**Post date:** [November 29, 2019, 10:28am UTC](https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195/3 "2019-11-29T10:28:31Z")

</div>

You can use TSoftObjectPtr property in your blueprint to store a path to objects in your content folder. If you move these objects around in the editor the paths will automatically update plus you can load the objects only when you need them. The downside is that as your project grows this doesn’t scale very well.

A better way is to customize UAssetManager for your project and use the FPrimaryAssetId system. This lets you use string identifiers to stream in any asset in your game on demand. But it requires a bit of setup and planning to work correctly.

---

<div class="post-metadata">

**Author:** ![Bitwaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bitwaker](https://forums.unrealengine.com/u/Bitwaker)\
**Post date:** [November 30, 2019, 3:14pm UTC](https://forums.unrealengine.com/t/loadobject-without-hardcoding-the-file-path/134195/4 "2019-11-30T15:14:33Z")

</div>

Thank you Waves!

> [@Waves](#):
>
> A better way is to customize UAssetManager for your project and use the FPrimaryAssetId system. This lets you use string identifiers to stream in any asset in your game on demand. But it requires a bit of setup and planning to work correctly.

Very interesting I will try this immediately!
