Error C2227 when use TSoftObjectPtr?

I want to load a static mesh asychronously, when using TSoftObjectPtr, an compile error occurs:

error C2227: left of ‘->Get’ must point to class/struct/union/generic type

My code:

FString Filepath;
TSoftObjectPtr<UStaticMesh> StmPtr(FSoftObjectPath(Filepath));
UStaticMesh* StMesh = StmPtr->Get();//error C2227

Any suggestion here? thank you so much!

It’s StmPtr.Get().
The TSoftObjectPtr is an object that points to your static mesh. Using → accesses your mesh, using a period accesses the pointer itself, which you want, since it’s the pointer that has the Get function.

Thank you for your aswner, but another error occurs:

error C2228: left of ‘.Get’ must have class/struct/union

code:

TSoftObjectPtr<UStaticMesh> StmPtr(FSoftObjectPath(FString()));
UStaticMesh* StMesh = StmPtr.Get();//error C2228

I just checked your code, apparently that way of constructing a TSoftObjectPtr isn’t valid in the first place and the compiler thinks ithe StmPtr(FSoftObjectPath(String)) is a function call instead of a constructor of an object.

Generally, it seems like you need one or the other (TSoftObjectPtr or FSoftObjectPath), not both. Either use TSoftObjectPtr<UStaticMesh> StmPtr = Mesh; or FSSoftObjectPath(Filepath).

You are right. I have changed my code to:

FString Filepath;
UStaticMesh StMesh = nullptr;
FSoftObjectPtr MeshPtr = FSoftObjectPtr(FSoftObjectPath(Filepath));
StMesh = Cast<UStaticMesh>(MeshPtr.Get());

No errors now.