Hello. I have some troubles about an Editor script I’m working on. Basically I’d like to check if a selected Asset in the content browser is an Actor Blueprint which has a InstancedMeshComponent. I’m pretty new in Unreal, so for me it sounds so simple, like in Unity GetComponent. I’ve tried many solutions but none of them work.
The blueprint i wanna check is a simple Actor one, where i simply pressed + to add the InstanceMeshCompoenent.
here the script I tried to write in c++. Till Go2 it works, after i don’t know what happens but it doesn’t work. I know probably it’s garbage so feel free to completely rewrite it, any suggestion is more than wellcome, thanks in advance.
if (UBlueprint* Blueprint = Cast(SelectedAssets[1].GetAsset()))
{
UE_LOG(LogTemp, Error, TEXT(“GO 0 %s”), *Blueprint->GetName());
if (UClass* BlueprintClass = Blueprint->GeneratedClass)
{
UE_LOG(LogTemp, Error, TEXT("GO 1 %s"), *BlueprintClass->GetName());
UObject* DefaultObject = BlueprintClass->GetDefaultObject();
if (AActor* DefaultActor = Cast<AActor>(DefaultObject))
{
UE_LOG(LogTemp, Error, TEXT("GO 2 %s"), *DefaultObject->GetName());
UInstancedStaticMeshComponent* InstancedMeshComponent =
DefaultActor->FindComponentByClass();
if (InstancedMeshComponent)
{
UE_LOG(LogTemp, Warning, TEXT(“UInstanceStaticMesh found”));
if (InstancedMeshComponent->GetStaticMesh() && InstancedMeshComponent->GetNumMaterials() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("UInstanceStaticMesh valid"));
return InstancedMeshComponent;
}
else
{
UE_LOG(LogTemp, Error, TEXT("InstancedStaticMeshComponent found but not valid."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("InstancedStaticMeshComponent not found."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to cast DefaultObject to AActor."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to get BlueprintClass."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT(“Failed to cast selected asset to UBlueprint.”));
}