Scripting a Particle System in World

I am fairly new to Udon and world building. In my world I have a basic Particle System called “WorldParticles”. I am using the UdonSharp package to code in C# and attempting to have a UI slider adjust the maximum particle count. My basic program is as follows and I have screen snipped my UI slider component inspector. Everything compiles OK, the Particle System is working as defaulted to and the slider moves just fine in VRC, but of course, nothing happens when to the Particle System when I adjust the slider. Am I sending the wrong UdonBehaviour event?

![inspector|278x499](upload://9zd8DTwsKob5HCbvhIvHRSFgYEI.png)
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using UnityEngine.UI;

public class WorldAdjustments : UdonSharpBehaviour
{

    private Slider _sliderMaxParticles;

    public ParticleSystem particles;

    void Start()
    {
        _sliderMaxParticles = transform.GetComponent<Slider>();
        particles = GetComponent<ParticleSystem>();
    }

    public void updateMaxParticles()
    {
        var main = particles.main;
        var emission = particles.emission;
        main.maxParticles = (int)_sliderMaxParticles.value;
        emission.rateOverTime = main.maxParticles / 2.0f;

    }
}

your
particles = GetComponent<ParticleSystem>();

in start is probably setting your particles variable to null (unless particle system is attached to the same game object)

And yes, since it’s not a SendCustomEvent, but you can just call the function directly

For example you can write it like this
Which would allow you to simply call the function whenever the value gets changed
image

;

public void override interact()
    {
        var main = particles.main;
        var emission = particles.emission;
        main.maxParticles = (int)_sliderMaxParticles.value;
        emission.rateOverTime = main.maxParticles / 2.0f;

    }
1 Like

Other than correcting the declaration to the following, your suggestions worked and were extremely helpful! Thank you! :slightly_smiling_face:
public override void Interact()