How to get inherited Mesh Component to show in BP editor?

I’m sure this’ll end up with a simple answer, but I cannot for the life of me figure it out. In the base C++ class of which the Blueprint is based on, I have a Scene Component as its root and a Static Mesh Component for visual representation. All this is being done in the constructor.

AFoodBase::AFoodBase()
{
	PrimaryActorTick.bCanEverTick = false;
	USceneComponent* SC = CreateDefaultSubobject(TEXT("Root Component"));
	RootComponent = SC;
	UStaticMeshComponent* Mesh = CreateDefaultSubobject(TEXT("Mesh"));
	Mesh->SetStaticMesh(ObjectMesh);
	Mesh->SetRelativeLocation(FVector(0.f, 0.f, -5.f));
}

(because the tags are breaking, see picture for complete code)

The mesh I want to use in for the visual representation is set in the editor through the variable ObjectMesh declared in the class’ header. However, the mesh set in the editor doesn’t show up in the blueprint editor. Which while survivable, is just a pain to work with.

Now, to get around this I could just hard-code the mesh’s location into the code, specifically the constructor, but I don’t want to do that for obvious reasons. To get to show the mesh during gameplay, I’d need to move Mesh->SetStaticMesh(ObjectMesh); into the BeginPlay() function. However, what I don’t know how to do is get the mesh to show up in the BD editor window.

Any help figuring out how to show it in said window would be much appreciated.

Cheers

Piccadi11y

You should declare mesh component as, for example, UPROPERTY(VisibleAnywhere, EditDefaultsOnly). With it you can set mesh directly into this component in editor.

As you can see in the top right of the second screenshot (of the bp editor), I do have the capacity to set a mesh to be used. This is done in the header file with the UPROPERTY(EditAnywhere, Category = Fruit Variables) macro. As you can also see, I have selected a mesh of mine to be used. The problem is the UStaticMeshComponent (on the left, child to the USceneComponent[root]) isn’t being updated in editor to visually reflect this. I.e. the mesh doesn’t appear in the viewport. Will adding either of your suggestions to the UPROPERTY() macro allow this to happen, or is another solution needed?

I don’t understand why you want to set static mesh using some additional variable, if you can select staticmeshcomponent in editor and set it from there.

Anyway, if you want to do this through variable in Editor - you must make it in ConstructionScript or use PostEditChangeProperty() function.

Here is an example:

header:

	//Override PostEditChangeProperty
#if WITH_EDITOR
	virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif

cpp:

//Update with changed property
#if WITH_EDITOR
void AFoodBase::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);
	FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
	if (PropertyName == TEXT("ObjectMesh"))
	{
		Mesh->SetStaticMesh(ObjectMesh);
	}
}
#endif

While redbox’s answer did result in results very similar to what I needed, it wasn’t quite there. After rethinking the problem, the way I’m going about implementing the class’ functionality doesn’t allow for the visual feedback I was after. For this reason I’m going to mark this question as answered and hope that someone who finds there way here can either get the help they need from it (it’s very valid code) or come to the same conclusion as me.

Cheers redbox for your help. Like I said in the post I’ve marked as answered, the help you’ve given me answered the question I was asking, just not the question I thought I was trying to ask. Thanks again for your time.