How to create a ParticlesMaterial in Code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rolfpancake
:warning: Old Version Published before Godot 3 was released.

I am trying to randomize some Particles2D instances.

Instancing the Particles2D Nodes and randomizing the object members (like amount, explosiveness and such) works fine. But when assigning a ParticlesMaterial to the process_material member I can’t instance a new ParticlesMaterial. This leads to the effect that when randomizing the ParticlesMaterial members (like initial_velocity, color and such) all Particles2D Nodes receiving the change. I would like to have seperate materials for each Particles2D Node.

# I want to get rid of this by creating a new ParticlesMaterial in code:
onready var particles_material = preload("res://particlesmaterial.tres")

var particles_reference = Particles2D.new()
particles_reference.process_material = particles_material   # <--

Is this somehow possible?

Thanks in advance.

:bust_in_silhouette: Reply From: rolfpancake

It is easy as that:

var particles = Particles2D.new()
particles.process_material = ParticlesMaterial.new()