Topic: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

http://i.imgur.com/h2b3aIA.png

In this tutorial, I'll show you how to mod in XWeaponTrail to add hit trails to your moves.  You will need to install the XWeaponTrail asset before starting, and make sure you have version 1.5 of UFE.

This mod is a fairly involved, and will also require some changes to how you'd normally setup your XWeaponTrail particles (see the final section under all the code changes).

As always, post below if you get stuck or if I missed anything.

------

In MoveSetScript.cs, look for:

public class ParticleInfo:ICloneable {

and inside this class under the bodypart declaration, add in:

    // X-Weapon Trail support
    public bool isWeaponTrail;
    public BodyPart bodyPartEnd;  // This is X-Weapon's EndPoint; bodypart is StartPoint

------

Then create a new script called StopParticleDelay.cs.  We need this to allow for better control of stopping the XWeaponTrail particle.  Replace the default code generated with the below code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class StopParticleDelay : MonoBehaviour {

    // Script that uses delay to stop a particle smoothly (instead of Destroy)

    public float stopDelay;

    private float startTime;

    private ParticleSystem[] myParticleSystems;
    private Xft.XWeaponTrail myWeaponTrail;

    // Use this for initialization
    void Start () {
        myParticleSystems = GetComponentsInChildren<ParticleSystem>();

        myWeaponTrail = GetComponent<Xft.XWeaponTrail>();

        startTime = Time.timeSinceLevelLoad;
    }
    
    void FixedUpdate () {
        if (Time.timeSinceLevelLoad >= startTime + stopDelay) {
            foreach(ParticleSystem system in myParticleSystems) {
                system.Stop(true);
            }
            
            if (myWeaponTrail != null) {
                myWeaponTrail.StopSmoothly(0.2f);
            }
            
            Destroy(gameObject, 2.0f);
        }
    }

    public IEnumerable DelayedStop(float delay) {

        Debug.Log ("Starting DelayedStop " + Time.timeSinceLevelLoad);

        yield return new WaitForSeconds(delay);

        foreach(ParticleSystem system in myParticleSystems) {
            system.Stop(true);
            Debug.Log ("Stopping Particle " + system.name + ", " + Time.timeSinceLevelLoad);
        }

        if (myWeaponTrail != null) {
            myWeaponTrail.StopSmoothly(0.5f);
        }

        Debug.Log ("Destroying GO " + Time.timeSinceLevelLoad);
        Destroy(gameObject, 2.0f);

    }


}

------

Then in ControlsScript.cs, look for:

// Check Particle Effects
foreach (MoveParticleEffect particleEffect in move.particleEffects){

and replace the foreach loop with the below:

        // Check Particle Effects
        foreach (MoveParticleEffect particleEffect in move.particleEffects){
            if (
                !particleEffect.casted && 
                particleEffect.particleEffect.prefab != null &&
                move.currentFrame >=  particleEffect.castingFrame
                ){

                particleEffect.casted = true;

                Vector3 newPosition = myHitBoxesScript.GetPosition(particleEffect.particleEffect.bodyPart);

                GameObject pTemp;
                    
                if (particleEffect.particleEffect.isWeaponTrail) {

                    pTemp = (GameObject) Instantiate(particleEffect.particleEffect.prefab,
                                               newPosition,
                                               Quaternion.identity);

                    
                    Vector3 endPosition = myHitBoxesScript.GetPosition(particleEffect.particleEffect.bodyPartEnd);

                    pTemp.transform.parent = myHitBoxesScript.GetTransform(particleEffect.particleEffect.bodyPart);
                    
                    Xft.XWeaponTrail xComp = pTemp.GetComponent<Xft.XWeaponTrail>();

                    xComp.PointStart.position = newPosition;
                    xComp.PointEnd.position = endPosition;

                } else {

                    newPosition.x += particleEffect.particleEffect.offSet.x * -mirror;
                    newPosition.y += particleEffect.particleEffect.offSet.y;
                    newPosition.z += particleEffect.particleEffect.offSet.z;

                    pTemp = (GameObject) Instantiate(particleEffect.particleEffect.prefab,
                                                     newPosition,
                                                     Quaternion.identity);

                    if (particleEffect.particleEffect.stick) pTemp.transform.parent = myHitBoxesScript.GetTransform(particleEffect.particleEffect.bodyPart);

                }

                StopParticleDelay spComp = pTemp.GetComponent<StopParticleDelay>();
                
                if (spComp != null) {
                    spComp.stopDelay = particleEffect.particleEffect.duration;
                } else {
                    Destroy(pTemp, particleEffect.particleEffect.duration);
                }

            }
        }

------

Then to add it to the Move Editor, open MoveEditorWindow.cs and look for:

for (int i = 0; i < moveInfo.particleEffects.Length; i ++){

and replace this for loop with the below code:

                        for (int i = 0; i < moveInfo.particleEffects.Length; i ++){
                            EditorGUILayout.Space();
                            EditorGUILayout.BeginVertical(arrayElementStyle);{
                                EditorGUILayout.Space();
                                EditorGUILayout.BeginHorizontal();{
                                    moveInfo.particleEffects[i].castingFrame = EditorGUILayout.IntSlider("Casting Frame:", moveInfo.particleEffects[i].castingFrame, 0, moveInfo.totalFrames);
                                    if (GUILayout.Button("", "PaneOptions")){
                                        PaneOptions<MoveParticleEffect>(moveInfo.particleEffects, moveInfo.particleEffects[i], delegate (MoveParticleEffect[] newElement) { moveInfo.particleEffects = newElement; });
                                    }
                                }EditorGUILayout.EndHorizontal();
                                if (moveInfo.particleEffects[i].particleEffect == null) moveInfo.particleEffects[i].particleEffect = new ParticleInfo();

                                moveInfo.particleEffects[i].particleEffect.isWeaponTrail = EditorGUILayout.Toggle("X Weapon Trail:", moveInfo.particleEffects[i].particleEffect.isWeaponTrail, toggleStyle);

                                if (moveInfo.particleEffects[i].particleEffect.isWeaponTrail) {
                                    moveInfo.particleEffects[i].particleEffect.prefab = (GameObject) EditorGUILayout.ObjectField("X-Weapon Trail Prefab:", moveInfo.particleEffects[i].particleEffect.prefab, typeof(UnityEngine.GameObject), true);
                                    moveInfo.particleEffects[i].particleEffect.duration = EditorGUILayout.FloatField("Duration (seconds):", moveInfo.particleEffects[i].particleEffect.duration);
                                    EditorGUI.BeginDisabledGroup(moveInfo.particleEffects[i].particleEffect.isWeaponTrail);{
                                        moveInfo.particleEffects[i].particleEffect.stick = EditorGUILayout.Toggle("Sticky", true, toggleStyle);
                                    }EditorGUI.EndDisabledGroup();
                                    moveInfo.particleEffects[i].particleEffect.bodyPart = (BodyPart) EditorGUILayout.EnumPopup("Inner Point:", moveInfo.particleEffects[i].particleEffect.bodyPart, enumStyle);
                                    moveInfo.particleEffects[i].particleEffect.bodyPartEnd = (BodyPart) EditorGUILayout.EnumPopup("Outer Point:", moveInfo.particleEffects[i].particleEffect.bodyPartEnd, enumStyle);

                                } else {

                                    moveInfo.particleEffects[i].particleEffect.prefab = (GameObject) EditorGUILayout.ObjectField("Particle Effect:", moveInfo.particleEffects[i].particleEffect.prefab, typeof(UnityEngine.GameObject), true);
                                    moveInfo.particleEffects[i].particleEffect.duration = EditorGUILayout.FloatField("Duration (seconds):", moveInfo.particleEffects[i].particleEffect.duration);
                                    moveInfo.particleEffects[i].particleEffect.stick = EditorGUILayout.Toggle("Sticky", moveInfo.particleEffects[i].particleEffect.stick, toggleStyle);
                                    moveInfo.particleEffects[i].particleEffect.bodyPart = (BodyPart) EditorGUILayout.EnumPopup("Body Part:", moveInfo.particleEffects[i].particleEffect.bodyPart, enumStyle);
                                    moveInfo.particleEffects[i].particleEffect.offSet = EditorGUILayout.Vector3Field("Off Set (relative):", moveInfo.particleEffects[i].particleEffect.offSet);
                                }
                                EditorGUILayout.Space();
                            }EditorGUILayout.EndVertical();
                        }

------

Lastly, in XWeaponTrail.cs, to ensure the trail particle is destroyed change the Deactivate() method with the below:

        public void Deactivate()
        {
            gameObject.SetActive(false);
            if (mMeshObj != null) {
                mMeshObj.SetActive(false);
                Destroy(mMeshObj);
            }

            Destroy(gameObject);
        }

=============

http://i.imgur.com/OGjfUHc.png

To make the XWeaponTrail prefab compatible, you'll need add the StopParticleDelay script to the gameobject.  Also, set your trail's color here.  In my example above I have two trails, one in white and another in pink. 

You should also adjust your Max Frame, Granularity and FPS to suit your game.  I've found higher Max Frame creates longer trails.  In my image above the pink trail has Max Frame of 30, and white has 60.

Share

Thumbs up +3 Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

You're the greatest, thank you so much for this!

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Is this going to be included in the next update of UFE?  I only ask because I know that updating the project will overwrite these changes and I think I read that particle effects will be updated in version 1.6 as well.  So using this code in the updated version will stop some of 1.6's functionality?

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

It's not planned yet.  But I can easily update it to work with 1.6 when the time comes.

Share

Thumbs up +2 Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Got it working now, Great work! big_smile

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Hi ,

I have successfully integrate that all code with my current UFE.

But when i add "x-weapon trail" in my particular move file. its added successfully.

But trail not display at runtime. I tired to resolve that problem,but i cant find the actual problem.

Can you inform me when i am wrong ?

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

SudhirKotila wrote:

But trail not display at runtime. I tired to resolve that problem,but i cant find the actual problem.

Hmm, not sure.  Run the game, and pause the player during the attack with the trail.  In the Hierarchy, drill down into the Game and Player GameObjects and see if you can see the trail there.  If it's not there, then it's not being instantiated (make sure the move is still within the frames the trail would be alive - turn debug on to check the move's current frame).

At least, this will give us some clues to what's going on...

Share

Thumbs up Thumbs down

8 (edited by SudhirKotila 2015-04-30 03:14:29)

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Yea you right.Trail is not instantiated. It was not showing in the hierarchy. Then can you guid me what now i should have to do for to resolve my problem ?

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Is your trail prefab created correctly?  Does it have the XWeaponTrail script attached?  Are you absolutely sure it's not instantiating, or is it instantiating in the root (which would mean the Sticky property hasn't been applied).  Lastly, are you sure you have gone through the tutorial 100% correct?

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Got this working in 1.6 no problem

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

YumChaGames wrote:

Is your trail prefab created correctly?  Does it have the XWeaponTrail script attached?  Are you absolutely sure it's not instantiating, or is it instantiating in the root (which would mean the Sticky property hasn't been applied).  Lastly, are you sure you have gone through the tutorial 100% correct?


Sorry for late reply.
Now my problem related to trail was solved and your tutorial is perfect.It's works very fine and so smooth.

Thank you so much.

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Hi i would just like to ask if anyone can help me with this one.. I followed all the instruction but i'm getting a lot of errors like this one.

Assets/UFE/Scripts/ControlsScript.cs(1210,67): error CS1061: Type `ParticleInfo' does not contain a definition for `isWeaponTrail' and no extension method `isWeaponTrail' of type `ParticleInfo' could be found (are you missing a using directive or an assembly reference?)

I'm using Unity 5.3.2.f1 and the latest version of xWeaponTrail(1.1.2), can anyone share their updated scripts or update this topic for guys like me who can't code? Thanks in advance..

Share

Thumbs up Thumbs down

13 (edited by hendrixlt 2016-06-07 00:18:51)

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

It's giving me the following error:

Assets/UFE/Scripts/StopParticleDelay.cs(51,39): error CS1061: Type `Xft.XWeaponTrail' does not contain a definition for `StopSmoothly' and no extension method `StopSmoothly' of type `Xft.XWeaponTrail' could be found (are you missing a using directive or an assembly reference?)

I'm still using 1.6

EDIT: SOLVED!

Share

Thumbs up Thumbs down

14 (edited by knightgabriel4eva 2016-09-29 04:54:51)

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

I am having trouble with adding weapon trail
especially with controlscript

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

knightgabriel4eva wrote:

I am having trouble with adding weapon trail
especially with controlscript

If you are posting that you'd like someone to help you out, I'd suggest posting more information so that people can direct you on how to resolve the trouble you're having.

Share

Thumbs up +1 Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

MrPonton wrote:
knightgabriel4eva wrote:

I am having trouble with adding weapon trail
especially with controlscript

If you are posting that you'd like someone to help you out, I'd suggest posting more information so that people can direct you on how to resolve the trouble you're having.

for ControlsScript.cs and MoveEditorWindow.cs
it said i should replace but since there are some changes or huge changes from 1.7 to 1.8
i dont know where to put them or if it's good idea to replace them

i managed to mirror particles though..

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

so any update on this tutorial?

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Is there any update on this?

Eternal Rift Studios
    Current Projects:
         Destined Soels
Always happy to help when possible. If its something pretty minor ill just help you out. But i do commissions as well. Hit me up if you need a commission.

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Is this still working for the latest versions of the software?

Share

Thumbs up Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Nope ive tried myself

Eternal Rift Studios
    Current Projects:
         Destined Soels
Always happy to help when possible. If its something pretty minor ill just help you out. But i do commissions as well. Hit me up if you need a commission.

Share

Thumbs up +1 Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

any new update on this?

"Battle Hard" - Trilateral

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

is there any other weapon trail, that anyone would recommend?

"Battle Hard" - Trilateral

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

Trail renderer

Its free and theres video for itbon youtube

Eternal Rift Studios
    Current Projects:
         Destined Soels
Always happy to help when possible. If its something pretty minor ill just help you out. But i do commissions as well. Hit me up if you need a commission.

Share

Thumbs up +1 Thumbs down

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

cool, will check it out, thanks

"Battle Hard" - Trilateral

25 (edited by Steviebops 2017-08-16 16:04:56)

Re: (Source) Advanced Tutorial: Hit trails using XWeaponTrail

I may have got this working again, Just checking some issues with destroying the particle trail, but they're very minor smile

Share

Thumbs up +2 Thumbs down