# How to get StaticMesh reference from the path of .uasset

**URL:** <https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707>\
**Category:** Pipeline & Plugins\
**Tags:** unreal-engine, CPP, question\
**Created:** [July 31, 2016, 3:22pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707 "2016-07-31T15:22:45Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [July 31, 2016, 3:22pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/1 "2016-07-31T15:22:45Z")

</div>

I give up Epic Games. Your “helpful C++” got me. I’ve read a lot of topics and docs about that:

> **[How to get asset by string reference?](https://forums.unrealengine.com/questions/401463/how-to-get-asset-by-string-reference.html)**
>
> I would like to create a Blueprint node using C++ that I can pass a string reference to an asset (specifically for Materials and Media Players) that will return the asset reference itself. For example, if I pass this string (for Material): ...

> **[Referencing Assets](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/Assets/ReferencingAssets/)**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

> **[\[TUTORIAL\] C++ - Runtime Async Load Modular Character (Intermediate)](https://forums.unrealengine.com/showthread.php?5309-TUTORIAL-C-Runtime-Async-Load-Modular-Character-%28Intermediate)**
>
> DISCLAIMER: This is a C++ tutorial if someone get interested on implement the Blueprint part, feel free to. 😉 Hi! Now, let’s suppose you are doing a game where you’ll need a “LOT” of character customization, imagine that your characters will need...

> **[How to get file list in a directory?](https://forums.unrealengine.com/questions/212791/how-to-get-file-list-in-a-directory.html)**
>
> I want to list all the file name in a directory, Is there any function available in unreal?

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

**but all solutions don’t work**.

I can get a list of my files. So I have an array of Fstring, but trying that:

```
.h
    UCLASS()
    class BATTERYCOLLECTOR_API UMyGameInstance : public UGameInstance
    {
    	GENERATED_BODY()
    public:
    		// Load a material from the corresponding path
    		UFUNCTION(BlueprintCallable, Category = "Asset Loading")
    		static UStaticMesh * LoadStaticMeshReference(const FString& materialPath);
    };

.cpp
UStaticMesh * UMyGameInstance::LoadStaticMeshReference(const FString& materialPath)
{
	FStringAssetReference assetRef(materialPath);
return Cast<UStaticMesh>(assetRef.TryLoad());
}

```

nothing happens. I tried to load using your favorite TAssetPtr but I don’t understand how to create it with FStringAssetReference? What is the

```
/**  
 * Copy from a unique object identifier
 * @param ObjectID Object identifier to create a weak pointer to
 */
FORCEINLINE void operator=(const FStringAssetReference &ObjectID)
	{
		AssetPtr = ObjectID;
	}

```

means?

What is the most simple and **understandable** way to get and load ObjectReference from any folders I want?

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [July 31, 2016, 3:28pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/2 "2016-07-31T15:28:06Z")

</div>

Did you try this?

```
UYourObjectClass* YourObject = Cast<UYourObjectClass>(StaticLoadObject(UYourObjectClass::StaticClass(), nullptr, *PathToYourObject));

```

I’m using this in one of my projects and it works without any problems.

Path I used here looks like:

> /Game/TestAssets/TeamAttitudes\_1.TeamAttitudes\_1

for object:

[](https://i.imgur.com/b3awBHK.png)

I didn’t test it in static function tho.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [July 31, 2016, 4:33pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/3 "2016-07-31T16:33:07Z")

</div>

Didn’t work.

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [July 31, 2016, 5:08pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/4 "2016-07-31T17:08:14Z")

</div>

Can you be more specific? It didn’t compile? It didn’t load the object? It doesn’t work in static function? It’s not what you want or what?

It does work for me:

[](https://i.imgur.com/EF1k5cO.gif)

When I use it like so

Header:

```
UPROPERTY(EditAnywhere, Category = "Test")
	FString Path;

	UPROPERTY(EditAnywhere, Category = "Test")
	UStaticMesh* TestMesh;

    virtual void OnConstruction(const FTransform& Transform) override;

```

Source:

```
void ACharacterBase::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	TestMesh = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, *Path));
}
```

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [July 31, 2016, 5:15pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/5 "2016-07-31T17:15:46Z")

</div>

LoadStaticMeshReference returns NULL.  
assetRef.isValid returns TRUE.

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [July 31, 2016, 5:26pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/6 "2016-07-31T17:26:22Z")

</div>

I’ve moved it to static function and it still works fine.

Can you show me where you use it? Also, double check if path is correct. I see that your variable for path is named ‘materialPath’ yet, you’re searching for static meshes. Dunno if you didn’t overlook it somewhere and you maybe still passing path to material or smth.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [July 31, 2016, 5:43pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/7 "2016-07-31T17:43:15Z")

</div>

I use this function in BP. for example in the actor

 ![100863-2016-07-31_23-40-14.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/2/b62ce2b75fdcdf50533cb629dd9d1c98074e62b4.png)

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [July 31, 2016, 5:53pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/8 "2016-07-31T17:53:51Z")

</div>

Afaik this method won’t work for absolute path of a file. It expects a relative path of an asset in current project.

If the file you’re trying to load is in project where you use that function, then you could convert that path to a relative one that is acceptable by this function.

Otherwise I have no other idea for now.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [July 31, 2016, 6:02pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/9 "2016-07-31T18:02:03Z")

</div>

But it doesn’t work with a relative too)))

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [August 4, 2016, 7:49am UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/10 "2016-08-04T07:49:17Z")

</div>

Upgraided VS to 2015 and tried exactly your code into blank 3Dcharacter but it doesn’t work at all. Idk man… What is going on here) This bug drives me crazy.

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [August 4, 2016, 11:18am UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/11 "2016-08-04T11:18:57Z")

</div>

Could you upload that blank project?

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [August 4, 2016, 12:06pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/12 "2016-08-04T12:06:27Z")

</div>

[LoadBro.rar — Yandex.Disk](https://yadi.sk/d/syVLhVPttv2K2) Here you are.

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [August 4, 2016, 12:23pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/13 "2016-08-04T12:23:23Z")

</div>

Okay, I’ll take a look at it in the evening.

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [August 4, 2016, 5:42pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/14 "2016-08-04T17:42:44Z")

</div>

You just sent me a project with no source. How am I supposed to check why your code doesn’t work if you didn’t send it?

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [August 4, 2016, 6:09pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/15 "2016-08-04T18:09:35Z")

</div>

I think source isn’t different on the same versions but i’m not sure in everything now) [LoadBro.rar — Yandex.Disk](https://yadi.sk/d/syVLhVPttv2K2)

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [August 4, 2016, 6:49pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/16 "2016-08-04T18:49:41Z")

</div>

I tested it and it works. 😛

Implementation, usage, and mat location:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/e/8ed37e4847a14b3c611899bb81deb49fd22c2458.png) ](https://i.imgur.com/fHE6ZVE.png)

Result in game:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/9/a9e36534423a00ff3bcca4cd149aa5d92125dd82.png) ](https://i.imgur.com/oMrfMxR.png)

Links to pics as these weren’t added automatically :\<

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/e/8ed37e4847a14b3c611899bb81deb49fd22c2458.png) ](https://i.imgur.com/fHE6ZVE.png)

[![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/9/a9e36534423a00ff3bcca4cd149aa5d92125dd82.png) ](https://i.imgur.com/oMrfMxR.png)

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [August 4, 2016, 7:17pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/17 "2016-08-04T19:17:06Z")

</div>

Wtf… How… Emm… “/” instead “” ? What is the Testmat.TestMat? And if only have \*\*\*.uasset files?  
Ok whatever. What about StaticMesh? Could you add static mesh component at character?

---

<div class="post-metadata">

**Author:** ![Atheist91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Atheist91](https://forums.unrealengine.com/u/Atheist91)\
**Post date:** [August 5, 2016, 9:46am UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/18 "2016-08-05T09:46:05Z")

</div>

This function will work only for asset files, yes.

If you want to search for static mesh using this, simply change UMaterial to UStaticMesh.

TestMat.TestMat is… a way references to assets are represented in UE4. I don’t know why to be honest. Basically you have to repeat your asset name after a dot. So since I was searching for material called ‘TestMat’, my path contained ‘[…]/TestMat.TestMat’ at the end.

---

<div class="post-metadata">

**Author:** ![Two-faced](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Two-faced](https://forums.unrealengine.com/u/Two-faced)\
**Post date:** [August 5, 2016, 12:29pm UTC](https://forums.unrealengine.com/t/how-to-get-staticmesh-reference-from-the-path-of-uasset/365707/19 "2016-08-05T12:29:17Z")

</div>

Where could I found this information about different backslashes and this ■■■■ extensions… wtf((( It took me 2 weeks to solve this problem! Nobody told me about proper path format… All specs tried to offer a different solution and noone didn’t look to the essence. LMAO ))  
Thank you anyways) You’re the best, man)
