CpuParticles2D instantiated through script can't be seen

Using the latest release of 4.3 and I’m still pretty new to the engine

Right now I’m trying to instantiate the node to create a little explosion visual effect when a die gets rolled, the node properly appears in the scene tree when viewing the remote tree but it never appears in the game world. I’ve ensured the visible flag is enabled and messed around with the scale to make sure the effect wouldn’t be lost to the eye.

Is it set to emitting when the particles are added to the scene? Can you share your code?

1 Like

It’s hard to say for sure without seeing your code, but I often get tripped up when creating objects dynamically because I don’t add_child(object) to get it in the scene proper. Might that be your issue?

1 Like

This is my code including all of the options I’ve enabled simply for debugging purposes.

public partial class Dice_Particles : CpuParticles2D {

	public override void _Ready() {
		Position = new Vector2(400, 500);
		Curve scale_curve = new Curve();
		scale_curve.MaxValue = 1;
		scale_curve.MinValue = .01f;

		Curve accel_curve = new Curve();
		accel_curve.MaxValue = 80;
		accel_curve.MinValue = -10;
		
		ScaleAmountMax = 1000;
		ScaleAmountMin = 3;
		Visible = true;
		
		Emitting = true;
		OneShot = false;

		Explosiveness = .88f;
		SpeedScale = .9f;
		Randomness = .3f;
		Spread = 180f;
		ScaleAmountCurve = scale_curve;
		Color particle_color = new Color();
		particle_color.R = 255;
		particle_color.A = 255;
		LinearAccelCurve = accel_curve;
		InitialVelocityMax = 70;
		InitialVelocityMin = 20;

		Color = particle_color;
		Amount = 100;
		TopLevel = true;
	}
...

This is how it’s being added to the scene, I have tried instantiating it through a c# script instead of gdscript but I experience the same result.

func _ready():
...
    particle_script = load("res://scripts/utils/Dice_Particles.cs")
	particle_controller = particle_script.new()
	add_child(particle_controller)

Try either setting the position after it’s added to the tree, since position is relative to parent, or using global position instead.