Static mesh property

I have an abstract C++ class that is intended to be expanded upon with Blueprints.

This class has a bunch of default fields that I would like to be able to set in Blueprints.

One of those fields will be a settable static mesh asset.

IE, I can tell this Blueprint in it’s defaults what static mesh I would like.

How would I go about doing that?

Thanks, -.

I guess you know how to use UProperty to expose things to the editor/blueprint.

UPROPERTY()
UStaticMesh* mesh;

should expose a static mesh in the editor and blueprint, could be that you need to set some blueprint properties into UPROPERTY ( … )

Wow that was super easy, thanks.

So when this property is updated / changed in the editor, how would I know in the C++ class? IE, when the static mesh is changed I’d like to add a Static Mesh component.

The way to do this is simply add a StaticMeshComponent to the actor, and in Blueprint you can then set the ‘mesh’ of that component.



UPROPERTY(VisibleDefaultsOnly, Category = "Mesh")
UStaticMeshComponent* ObjectMesh;


Be aware: Don’t make this an ‘Edit Defaults Only’ object or you’ll get really screwed up behaviour!

Sorry to be a PITA.

The C++ class is derived from USceneComponent.


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Components/SceneComponent.h"
#include "Part.generated.h"

UCLASS(Abstract, Blueprintable, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class EDITOR_API UPart : public USceneComponent
{
	GENERATED_BODY()

public:

	// Sets default values for this component's properties
	UPart();

	// Called when the game starts
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

protected:

	// All parts have a credit cost to purchase from the store
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Part Properties")
	int32 CreditCost = 0;

	// ...

	// All parts have one single static mesh
	UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category = "Part Properties")
	UStaticMeshComponent * ObjectMesh;
	
};


These “Parts” will hopefully go together to build things, think the rockets in KSP, the “thing” I hope to be an actor.

So parts are components, the finished custom vehicles are Actors. At least that’s the idea.

Since this is a component, it’s my understanding that it CAN have sub components, like a static mesh, but when I subclass it with a Blueprint I don’t get the Component view like I would with an Actor.

Oh I see…

Yeah components ‘can’ have sub-components since they can also use the ObjectInitializer constructor, but last time I tried to do that I had all manner of issues with it since a lot of the ActorComponents’ properties are set based on it’s owning ‘Actor’. I ended up adding the components to the owning Actor instead, though still as part of the Constructor.