Immediately apologize for my english.
I have some interesting problem.
I have task to change static meshes in runtime via C++.
And I found 2 ways to implement this task:
Create direct object references via the method “ConstructorHelpers::FObjectFinder” in Constructor of Class:
UStaticMesh *MeshForLoad;
auto Mesh = ConstructorHelpers::FObjectFinder<UStaticMesh>( TEXT( "StaticMesh' PathToObject'"));
if ( Mesh.Object )
{
MeshForLoad = Mesh.Object;
}
Then in Component start method SetStaticMesh( MeshForLoad);
That way is hardway to designers - I created code, but designers cannot have access for reference change without editing code.
Create DataTable via struct, and via TAssetPtr load objects. So. It way very cool and easy for architecture, but I have problem.
I create struct MeshList with Property TAssetPtr <UStaticMesh> MeshPtr;
I create DataTable from struct MeshList.
Designer setup some meshes (like 2-3 references).
Via Code I find references, try to **SetStaticMesh( MeshPtr.Get() ). **But. Mesh does not want to load. Method “Get()” return null. As far as I understand - TAssetPtr stores a link to the location of the object (in my case - location of the Static Mesh).
Okey, I found information about AssetManager (and StreamableManager). That objects can help me to load my assets. BUT.
I Cannot find informantion about how create that objects (how initialize instance for work with it). In Documentation all examples are based on the fact that the object of AM (or SM) has already been created.
Or, in some case we have singleton, which (like witch) not work in 4.22.1 =(
MeshForLoad = Cast<UStaticMesh>( CustomMesh.ResolveObject() );
if ( MeshForLoad == nullptr )
{
MeshForLoad = Cast<UStaticMesh>( CustomMesh.TryLoad() ); // Load asset if not already loaded, this is slow...
}
That way people using the editor can just set the value of CustomMesh and in code you can use whatever mesh they inserted there.
Note: This is Unreal 4.20 ~ 4.22 API, in older versions this might not work at all.
That is not load, FSoftObjectPath only store infomation about the path to the object that is already loaded, if u want to load obj, u should use TAssetPtr and AssetManager. Pls correct me if i wrong but ue’s documentation wrote that.
[USER=“434”]BrUnO XaVIeR[/USER] Hi. Can you help me again?
I need to load U**UserWidget **to my WidgetComponent in AActor.
I set link to file via FSoftObjectPath.
File found, worked (I mean, if branch see him). Its not nullptr.
BUT. I can’t Cast UObject to UUserWidget (Or my type like UWidgetTest which parant for my Widget that I tryed to load(If you understand my bad english =)) ))
So. How can I setup my Widget to Component (via c++, of course).
Thanks a lot =) But I still have problem. There I wrote some interesting behavior, when I try to use TSubclassOf.
In Short - its works wile I have open Editor. When it close and restart - I have problem - crash and errors =(