How can i make a reference to a static mesh in c++

I want to change a static mesh’s Material in runtime,so I must take a reference to the mesh, how can I get it?
I had search for this question, someone use
ConstructorHelpers::FObjectFinder,I tried it
but when I run the game it says:

FObjectFinders can’t be used outside of constructors to find EditorPlane

this is the code:


static ConstructorHelpers::FObjectFinder findresult(TEXT(“EditorPlane”));
I fill this line in this function

Is there something wrong?or this is not a constructors?

I have done this with the following in beginplay, it should work elsewhere though.

    TArray<UStaticMeshComponent*> comps;
    this->GetComponents<UStaticMeshComponent>(comps);
    if(comps.Num()>0) MeshReference=comps[0];

This returns a pointer (MeshReference) to the first static mesh component.

MeshReference is defined in my .h file as

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Physics Control")
    UStaticMeshComponent* MeshReference;

error C2039: ‘GetComponents’ : is not a member of ‘FShooterMainMenu’

“this” in my case is an AActor class. I take it yours is not? If not, my answer is not valid for you.