Hi,
I’ve created a custom USynthComponent class to generate sound. The sound generator has a few parameters to allow manipulating the output sound, e.g. things like filters, frequencies, amplitudes etc. These parameters have default values that are specified in the declaration of the USynthComponent class. Here’s what that looks like:
UCLASS(ClassGroup = Synth, meta = (BlueprintSpawnableComponent))
class MYAUDIOPLUGIN_API UTestSFX : public USynthComponent
{
// Constructor
GENERATED_BODY()
UTestSFX(const FObjectInitializer& ObjInitializer);
// Destructor
virtual ~UTestSFX();
public:
// The frequency (in hz) of the tone generator.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", meta = (ClampMin = "10.0", ClampMax = "20000.0"))
float Frequency = 80.0;
// The volume of the tone generator.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", meta = (ClampMin = "0.0", ClampMax = "1.0"))
float Volume = 0.8;
// The Attack time of the envelope.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", meta = (ClampMin = "0.01", ClampMax = "5.0"))
float Attack = 0.5;
// The Decay time of the envelope.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", meta = (ClampMin = "0.01", ClampMax = "5.0"))
float Decay = 0.3;
// The cut-off frequency of the filter.
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Settings", meta = (ClampMin = "50.0", ClampMax = "15000.0"))
float Cutoff = 3000.0;
// Override USynthComponent's CreateSoundGenerator function with our own
virtual ISoundGeneratorPtr CreateSoundGenerator(int32 InSampleRate, int32 InNumChannels) override;
protected:
// The runtime instance of the sound generator
ISoundGeneratorPtr MyOsc;
};
As you can see, the default values are specified as UProperties. When dragging this component in a blueprint, these properties appear in the “Details” panel as sliders:
And you can see that the default position of the sliders matches the values in the code. Now for my problem: I would like to implement a preset system that would allow the user to load another set of default values. For example here the preset is (80, 0.8, 0.5, 0.3, 3000) and maybe I’d like a “flute” preset where the values are (250, 0.2, 0.6, 0.7, 9000).
I haven’t found any way of doing this yet. Is there a way to save the settings of a Ucomponent as a preset? How would you implement this?