Static mesh from blueprint

If you have the Actor pointer you can call the templated GetComponents function on it and get a list of all the components and then look in the returned array for the component name or type you are looking for.

I am currently trying to change the material of a blueprint at run time (on a key press for the time being). I have the framework setup and it loads up a blueprint I created and sets an instance of that blueprint in the scene. The blueprint itself holds a staticmesh (shape_sphere) which also has a material attached to it.

static ConstructorHelpers::FObjectFinder<UBlueprint> BallBlueprintAsset(TEXT("Blueprint'/Game/Blueprints/Ball.Ball'"));
	if (BallBlueprintAsset.Object != NULL)
	{
		BallBlueprint = (UClass*)BallBlueprintAsset.Object->GeneratedClass;
	}

Now I need something along the lines of BallBlueprint->GetStaticMesh() or BallBlueprintAsset->GetStaticMesh().

I believe I need to access the staticmesh of this blueprint somehow, so that I am then able to change the material of the mesh to something else in C++ code. Is this the right way to be going about this and does anybody have any other methods/pointers?

How exactly do I use the GetComponents function to find the static mesh? I found the documentation a little less then helpful, so at the moment I have got:

TArray<class UActorComponent*> ballComponentsArray;
BallList[i]->GetComponents(ballComponentsArray);

I got around this issue by making my actor a AStaticMeshActor. I then went through the process of loading up a material and then I was able to use the SetMaterial function from AStaticMeshActor’s class and easily set my material there.

	static ConstructorHelpers::FObjectFinder<UMaterial> BallMaterial(TEXT("Blueprint'/Game/Materials/BallMaterial.BallMaterial'"));
	m_BallMaterial = UMaterialInstanceDynamic::Create((UMaterial*)BallMaterial.Object, this);

	StaticMeshComponent->SetMaterial(0, m_BallMaterial);

However, I’m also looking at a way to change a texture of that material, but haven’t come across any methods for that yet.

Anyone looking to change a texture:

yourMaterial->SetTextureParameterValue(FName(TEXT("Ball_Texture")), textureIn);

textureIn is a UTexture2D* that I load in via:

static ConstructorHelpers::FObjectFinder<UTexture2D> MyObj(TEXT("/Game/Textures/SomeTexture.SomeTexture"));
UTexture2D* textureIn = MyObj.Object;

You also need to make sure you set your texture in your material to “Ball_Texture” or your texture name to change. Just thought I’d let anyone know which may also be getting lost like I was.