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
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.
Found the answer myself.
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
So first you create that struct:
UPROPERTY(BlueprintReadWrite, Instanced, EditAnywhere, export, noclear)
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
int FancyValue = 0;
FancyValue use your variables that you have in your base class.
And finally the children:
class YOURGAME_API UChildFoo : public UBaseFoo
I’m trying to do this as well but am running into linker errors. Can you elaborate on your solution?
I added some code to my answer. Does this help?
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:
class MYPROJECT_API UMyDamageType : public UDamageType
Then I add a property in my actor like the following
class MYPROJECT_API AMyActor : public AActor
// Sets default values for this actor's properties
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick(float DeltaTime) override;
When I create a child blueprint of AMyActor, I get this in the class defaults editor:
The secret is a combination of
EditInlineNew for the class and
Instanced for the attribute. Hope this can help someone else looking for this.