Topic: Destroy character move's particle effect after they get hit

I notice a bug happens where a character move's particle effect remain on screen after they get hit by an opponent (especially before they get a chance to finish the move).

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

Are you using destroy when move ends in the particle effect settings?
https://i.imgur.com/YcmYZVu.png

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: I don't use destroy when move ends because the particle doesn't even show up when the move is executed.

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

Seems like your doing a custom script to handle this then?

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

Where do I place this script, please? I will try it immediately.

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

apollo wrote:

Where do I place this script, please? I will try it immediately.

Place the script onto your character prefab.

I updated the script recently, I recommend using the new version due to the new disable Gameobject option. You will contribute less to the Garbage collecter if you use that option.

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: I added the script in my work and tested it; it didn't work. Nonetheless, I'll keep it in. Perhaps I can build upon it.

Thank you very much!

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

I did test it myself and it did work. Perhaps you missed something while setting it up?

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: I copied and pasted your script as is; and I added them to the prefabs of my characters.

I'm not using UFE particles. I'm using my own particles.

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

Did you forget to fill out the required fields?
https://i.imgur.com/bkd46su.png
Here's a video of it working.
https://imgur.com/a/eGiSdzm

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: You're right, I missed the adding the required fields. So you just add the moves, required prefabs, and position?
https://ibb.co/MgLtfk0

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: It works! It's a Christmas Miracle! Thank you very much and Happy Holidays!

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

Your welcome!
I think I could add an array to the prefabs option, that way you could easily create multiple objects per move.
I'll post a new updated script sometime.

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: Please consider time duration as well.

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

Here's a version with the timer.
Let me know if you need anything else for it.

Edit: Added an isn't null check to prevent errors.
Edit: This version is up to date.

using UnityEngine;
using UFE3D;

namespace FreedTerror
{
    public class UFE2FTEDestroyWhenMoveEnds : MonoBehaviour
    {
        private ControlsScript myControlsScript;

        [System.Serializable]
        public class PrefabOptions
        {                
            public MoveInfo move;
            public int spawnFrame;
            public GameObject prefab;
            [HideInInspector]
            public GameObject spawnedGameObject;  
            public bool sticky;
            public Vector3 spawnPosition;
            public bool mirrorOnRightSide;
            public bool destroyWhenMoveEnds;
            public bool destroyWhenTimerEnds;
            public float destroyDelay;
            [HideInInspector]
            public float destroyTimer;
            [Tooltip("If enabled, the spawned GameObject will be disabled instead of destroyed.")]
            public bool disableGameObject;
        }
        [SerializeField]
        private PrefabOptions[] prefabOptions;

        // Start is called before the first frame update
        void Start()
        {
            if (myControlsScript == null)
            {
                myControlsScript = GetComponentInParent<ControlsScript>();
            }
        }

        // Update is called once per frame
        void Update()
        {
            if (myControlsScript == null) return;

            int length = prefabOptions.Length;
            for (int i = 0; i < length; i++)
            {
                if (myControlsScript.currentMove != null
                    && myControlsScript.currentMove.moveName == prefabOptions[i].move.moveName
                    && myControlsScript.currentMove.currentFrame == prefabOptions[i].spawnFrame)
                {
                    if (prefabOptions[i].spawnedGameObject == null)
                    {
                        prefabOptions[i].spawnedGameObject = Instantiate(prefabOptions[i].prefab);

                        prefabOptions[i].destroyTimer = prefabOptions[i].destroyDelay;
                    }
                    else
                    {
                        prefabOptions[i].spawnedGameObject.SetActive(true);

                        prefabOptions[i].destroyTimer = prefabOptions[i].destroyDelay;
                    }

                    if (prefabOptions[i].sticky == true)
                    {
                        prefabOptions[i].spawnedGameObject.transform.parent = this.transform;
                    }
                    else
                    {
                        prefabOptions[i].spawnedGameObject.transform.parent = null;
                    }

                    if (prefabOptions[i].spawnedGameObject.transform.parent == null)
                    {
                        prefabOptions[i].spawnedGameObject.transform.position = this.transform.position + prefabOptions[i].spawnPosition;

                        if (myControlsScript.mirror == 1)
                        {
                            prefabOptions[i].spawnedGameObject.transform.position = new Vector3(this.transform.position.x + -prefabOptions[i].spawnPosition.x, prefabOptions[i].spawnedGameObject.transform.position.y, prefabOptions[i].spawnedGameObject.transform.position.z);
                        }
                    }
                    else
                    {
                        prefabOptions[i].spawnedGameObject.transform.localPosition = prefabOptions[i].spawnPosition;

                        if (myControlsScript.mirror == 1)
                        {
                            prefabOptions[i].spawnedGameObject.transform.localPosition = new Vector3(-prefabOptions[i].spawnedGameObject.transform.localPosition.x, prefabOptions[i].spawnedGameObject.transform.localPosition.y, prefabOptions[i].spawnedGameObject.transform.localPosition.z);
                        }
                    }

                    if (prefabOptions[i].mirrorOnRightSide == true)
                    {
                        if (myControlsScript.mirror == 1)
                        {
                            prefabOptions[i].spawnedGameObject.transform.localEulerAngles = new Vector3(prefabOptions[i].spawnedGameObject.transform.localEulerAngles.x, prefabOptions[i].spawnedGameObject.transform.localEulerAngles.y + 180, prefabOptions[i].spawnedGameObject.transform.localEulerAngles.z);
                        }
                    }
                }

                if (prefabOptions[i].destroyWhenMoveEnds == true)
                {
                    if (myControlsScript.currentMove == null
                        || myControlsScript.currentMove.moveName != prefabOptions[i].move.moveName)
                    {
                        if (prefabOptions[i].spawnedGameObject != null)
                        {
                            if (prefabOptions[i].disableGameObject == true)
                            {
                                prefabOptions[i].spawnedGameObject.SetActive(false);
                            }
                            else
                            {
                                Destroy(prefabOptions[i].spawnedGameObject);
                            }
                        }
                    }
                }

                if (prefabOptions[i].destroyWhenTimerEnds == true)
                {
                    if (prefabOptions[i].destroyTimer > 0)
                    {
                        prefabOptions[i].destroyTimer -= (float)UFE.fixedDeltaTime;
                    }
                    else
                    {
                        if (prefabOptions[i].spawnedGameObject != null)
                        {
                            if (prefabOptions[i].disableGameObject == true)
                            {
                                prefabOptions[i].spawnedGameObject.SetActive(false);
                            }
                            else
                            {
                                Destroy(prefabOptions[i].spawnedGameObject);
                            }
                        }
                    }
                }
            }
        }
    }
}

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

I got an error on line 132

prefabOptions[i].spawnedGameObject.SetActive(false);

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

I updated the script, thanks for the report.

Share

Thumbs up +1 Thumbs down

Re: Destroy character move's particle effect after they get hit

Thank you for the updates. It seems like the "time duration" is gone. Did you put the updates in a previous reply post?

Share

Thumbs up Thumbs down

Re: Destroy character move's particle effect after they get hit

I deleted the old script post.
Copy the post with the new code in it. You might have the old post's code still.
Your looking for destroy delay.
https://i.imgur.com/9djZ8CK.png

Share

Thumbs up +2 Thumbs down

Re: Destroy character move's particle effect after they get hit

@FreedTerror: It works! Thank you!

Share

Thumbs up +1 Thumbs down