Pass per-instance parameters to c++ class?

Is there a way to pass basic parameters like int, float, etc to a c++ per-instance in a manner that allows the c++ class to spawn components within itself that have static mobility such that the lighting build will catch them properly, but to allow a per-instance generation of objects?

For instance say I have a rack made of posts, struts, shelves, etc - it’s relatively straightforward to calculate where to place those static meshes and how to scale them to get a rack with x number of shelves of some arbitrary dimension without distorting the supports or shelf thicknesses - but whenever this is attempted within a blueprint it will crash saying you can’t spawn meshes and will usually corrupt the level until the blueprint is deleted. I know you can spawn components in a c++ class within the constructor but is there any way to get parameters into that constructor per-instance so I might use the same c++ class for a rack with 3 shelves or 4 shelves with arbitrary x/y/z dimensions as long as the dimensions and component counts and such don’t change thereafter?

I generally don’t like to suggest Blueprints unless really necessary, but in this case a Blueprint would be a good fit. I haven’t tried this myself, but I think it’s worth trying out.

I.e. suppose you have

in YourClass.h

UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 NumberOfShelves = 3;

UPROPERTY()
TArray<UStaticMeshComponent*> Shelves;

in YourClass.cpp

AYourActor::AYourActor()
{
	UStaticMeshComponent* mesh;
	FString meshName;
	
	for(int32 i = 0; i < NumberOfShelves; i++)
	{
		meshName = TEXT("StaticMeshComponent") + FString::SanitizeFloat(i);
		
		mesh = CreateDefaultSubobject<USkeletalMeshComponent>(meshName);
		Shelves.Add(mesh);
	}
}

Creating a Blueprint from this class allows you to set NumberOfShelves for each of the instances to whatever you like.