.h
#pragma once
#include "CoreMinimal.h"
#include "Kismemphasized textet/BlueprintFunctionLibrary.h"
#include "StatMeshLibrary.generated.h"
class UStaticMeshComponent;
/**
*
*/
UCLASS()
class YOURPROJ_API UStatMeshLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable)
static void SynchronizeStaticMesh(UPARAM(ref) UStaticMeshComponent* &smc, FString meshPath);
};
.cpp
void UStatMeshLibrary::SynchronizeStaticMesh(UPARAM(ref) UStaticMeshComponent* &smc, FString meshPath)
{
FString FindString = FPaths::Combine(TEXT("/Game"), meshPath, smc->GetName() + "." + smc->GetName());
if (FindString.Len() > 0) {
UStaticMesh* StaticMesh = LoadObject<UStaticMesh>(nullptr, *FindString);
if (StaticMesh != nullptr) {
smc->SetStaticMesh(StaticMesh);
}
}
}
Usage:
Use the mesh path if your static meshes are in a directory deeper than /Game