I have an Actor called PickupActor
Inside PickupActor, I add some components using CreateDefaultSubobject
e.g. m_meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(FName("NonSkelMesh"));
This works fine.
I want to set the StaticMesh on this. Initially I was using
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultSphereVisualAsset(TEXT("/Game/Dev/Test/BasicSphere.BasicSphere"));
m_meshComponent->SetStaticMesh(DefaultSphereVisualAsset.Object);
And this works. However several limitations with this.
- I don’t think the cooker/packager would see it.
- If that asset moves somewhere, the path will be outdated and it will fail.
I know I can manually overcome the cooker issue. But no good rename issue.
Second issue is that if the user defines a value in some external data.
Box: {
Mesh: "SomePath/WoodenBoxMesh",
}
LargeBox : {
Mesh: "SomePath/MetalBoxMesh",
}
I need to be able to select from 1 of multiple things, and that might need to happen after the CDO.
pickupItem = SpawnActor(loc, rot);
pickupItem.Initialize(InfoAboutWhatItemToMakeThis);
Which I can’t use ConstructorHelpers::FObjectFinder outside of constructor, and thus I can’t use anymore in ConstructorHelpers in this Initialize function.
I played around a little with LoadClass<UStaticMesh>(nullptr, TEXT("/Game/Test/BasicCube.BasicCube"));
But still similar issues.
Someone suggested I use UMasterDataAssetCpp, and implement a BP_UMasterDataAssetCpp and hook it into MyGameInstanceCpp and BP_MyGameInstancpp.
That way I can have TSoftObjectPtr defined in the UMasterDataAssetCpp but then set in the BP_ version, but still access it in the underlying cpp easily. This fixes the cooker AND the raw string issue! Yay! getting close!!
However, GameInstance doesn’t exist in the editor. It only exists after you hit Play/Simulate…
So if I want to drag/drop things into game, all the meshes are ‘empty’ until I hit play/simulate.
I’d like to be able to see the mesh inside the editor as well.
I started exploring GameSingletonClassName but having some issues with this as well.
Here are the things I want.
- I want to be able to set the mesh in C++. From an array of meshes.
- I want to be able to see the mesh in Editor before hitting Play.
- I want to do the ‘right’ thing by using TSoftObjectPtr and other things, for later on when I want to preload in AssetManager or AsyncLoad when the time is right.
- I don’t want to have a BP_ version for every class. This only shifts the problem.