If you create a new particle system and choose “Spawn”, you can change some properties (see image). One property is very handy, it’s called Distribution. First you can select what type do you want to have, like DistributionFloatConstant or DistributionFloatParticleParameter. Then it exposes the parameter for that specific type.
I want to build something like that in my own class. How can I do that?
I created an abstract C++ class and inherited from it. If I choose the “Reference of a Class”, I can only set the inherited class. But then I cannot set the parameters. If I choose “Reference of an instanced object”, I need to choose an asset but I don’t have one.
I think the most important part was, that you put a struct around the class. You always need that struct. If you want an array, make an array of structs and within these put your class.
The engine classes where helpful. Check DistributionFloat.h and ParticleModuleSpawn.h
This struct encapsulates your object. UPROPERTY is mostly copied from the engine classes. You can add additional variables in this struct.
Then you need the base class:
UCLASS(Blueprintable, DefaultToInstanced, collapsecategories, hidecategories = Object, editinlinenew, abstract)
class YOURGAME_API UBaseFoo : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int FancyValue = 0;
}
Instead of FancyValue use your variables that you have in your base class.
And finally the children:
UCLASS()
class YOURGAME_API UChildFoo : public UBaseFoo
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int ChildOnlyVariable;
}
It turns out the Struct is not necessary. If you add the EditInlineNew in the class you want to create in the properties window and Instanced in the attribute, you can create the object directly in the editor. Here is an example
I want to create this damage type in my blueprint class defaults:
UCLASS(Blueprintable, EditInlineNew)
class MYPROJECT_API UMyDamageType : public UDamageType
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float DamageAmount;
};
Then I add a property in my actor like the following
UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, Instanced)
UMyDamageType* DamageType;
};
When I create a child blueprint of AMyActor, I get this in the class defaults editor: