Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control particle position form script. #286

Closed
GabrielCoriiu opened this issue Jan 5, 2024 · 4 comments
Closed

Control particle position form script. #286

GabrielCoriiu opened this issue Jan 5, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request need more info

Comments

@GabrielCoriiu
Copy link

Hi,

This is a very nice project. Is there a way to create custom scripts for controlling the particles' position (and maybe some other properties)? I've tried subscribing to Canvas.willRenderCanvases, Canvas.preWillRenderCanvases as well as Update() and LateUpdate(), but none of them seems to be working. I checked how UIParticleAttractor works but it seems to be part of a closed system.

@GabrielCoriiu GabrielCoriiu added the enhancement New feature or request label Jan 5, 2024
@mob-sakai
Copy link
Owner

@GabrielCoriiu
Thank you for the feature request!

@mob-sakai
Copy link
Owner

@GabrielCoriiu
For example, the following component moves particles on Update. It works.

using UnityEngine;

[ExecuteAlways]
[RequireComponent(typeof(ParticleSystem))]
public class ParticleMovement : MonoBehaviour
{
    public ParticleSystem m_ParticleSystem;
    public Vector3 m_Move = Vector3.zero;

    private static readonly ParticleSystem.Particle[] s_Particles = new ParticleSystem.Particle[1024];

    private void Update()
    {
        if (!m_ParticleSystem || !m_ParticleSystem.IsAlive()) return;

        var count = m_ParticleSystem.particleCount;
        m_ParticleSystem.GetParticles(s_Particles);

        for (var i = 0; i < count; i++)
        {
            s_Particles[i].position += m_Move * Time.deltaTime;
        }

        m_ParticleSystem.SetParticles(s_Particles, count);
    }
}

@GabrielCoriiu
Copy link
Author

Thanks, I'll try it out. I only tried it from a component that was not attached to the same game object as the particle system, but a parent of it.

@mob-sakai
Copy link
Owner

Since there has been no new discussion for a long time, this issue was closed.

If the same issue arises, please re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need more info
Projects
None yet
Development

No branches or pull requests

2 participants