Announcement

Collapse
No announcement yet.

Need help implementing Particle System through UScript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help implementing Particle System through UScript

    I have this code so far that allows me to have "Damage States" for lack of a better term. I have it so when the KActor takes a set amount of damage it switches meshs, and I have it so it plays a soundcue. Both of these work, but everytime I try to get a particle system to work it never works. This code allows for the mesh, soundcue to be added from inside the editor by selecting the KActor and hitting F4 and playing with its properties, I need the Particle System to be able to be implemented this way as well. Does anyone have any ideas on how to do this, or can anyone help me do this?? Thanks for any help that can be given, and let me know if you need more info.
    Code:
    // Breakable Actor class, that is referanced by DarkJourneyBreakableActorFactory
    
    class DarkJourneyBreakableActor extends KActor
        config(Game)
        native
        placeable;
        
    // Types of Damage that are counted
    var() array<class<DamageType> > DamageTypes;
        
    struct native BreakableStep
    {
        // Total amount of damage to take before activating the event
        var() float         DamageThreshold;
        
        // KActor template to use when this object breaks
        var() StaticMesh    BreakMesh;
        
        // The physics mode to switch to
        var() EPhysics      Physics;
        
        // Sound to play when the object breaks or switches damage states
        var() SoundCue      BreakSound;
        
        structdefaultproperties
        {
            DamageThreshold = 0.0
            Physics = PHYS_RigidBody
        }
    };
    
    // Sequence of events of destruction.. starts at 0
    var() array<BreakableStep> BreakableSteps;
    
    // Current breakable step
    var int CurrentBreakableStep;
    
    native function vector GetOffsetToWorld(vector Offset);
    
    // Checks to see if the KActor has taken a valid damage type and if so changes the breakable step
    event TakeDamage(int Damage, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
    {
        if (IsValidDamageType(DamageType))
        {
            if (CurrentBreakableStep == BreakableSteps.Length - 1)
            {
                TakeLastDamage(Damage, EventInstigator, false, CurrentBreakableStep);
            }
            else
            {
                TakeStepDamage(Damage, EventInstigator, false, CurrentBreakableStep);
            }
        }
        Super.TakeDamage(Damage, EventInstigator, HitLocation, Momentum, DamageType, HitInfo, DamageCauser);
    }
    
    
    function TakeLastDamage(int Damage, Controller EventInstigator, bool bIsBroken, int BrokenStep)
    {
        BreakableSteps[CurrentBreakableStep].DamageThreshold -= Damage;
        if (BreakableSteps[CurrentBreakableStep].DamageThreshold < 0)
        {
            BreakLastApart(EventInstigator);
        }
        else if (bIsBroken)
        {
            BreakStepApart(BrokenStep);
        }
    }
    
    function TakeStepDamage(int Damage, Controller EventInstigator, bool bIsBroken, int BrokenStep)
    {
        BreakableSteps[CurrentBreakableStep].DamageThreshold -= Damage;
        if (BreakableSteps[CurrentBreakableStep].DamageThreshold < 0)
        {
            CurrentBreakableStep++;
            
            if (CurrentBreakableStep < BreakableSteps.Length - 1)
            {
                TakeStepDamage(-BreakableSteps[CurrentBreakableStep-1].DamageThreshold, EventInstigator, true, CurrentBreakableStep-1);
            }
            else
            {
                TakeLastDamage(-BreakableSteps[CurrentBreakableStep-1].DamageThreshold, EventInstigator, true, CurrentBreakableStep-1);
            }
        }
        else if (bIsBroken)
        {
            BreakStepApart(BrokenStep);
        }
    }
    
    // Searches DamageTypes[] for the specified damage type
    final function bool IsValidDamageType(class<DamageType> inDamageType)
    {
        local bool bValid;
        bValid = true;
        if (DamageTypes.Length > 0)
        {
            bValid = (DamageTypes.Find(inDamageType) != -1);
        }
        return bValid;
    }
    
    
    function BreakStepApart(int BrokenStep)
    {
        if (BreakableSteps[BrokenStep].BreakSound != None)
        {
            PlaySound(BreakableSteps[BrokenStep].BreakSound, true,,, CollisionComponent.Bounds.Origin);
        }
        
        if (BreakableSteps[BrokenStep].BreakMesh != None)
        {
            StaticMeshComponent.SetStaticMesh(BreakableSteps[BrokenStep].BreakMesh);
        }
        SetPhysics(BreakableSteps[BrokenStep].Physics);
        if(BreakableSteps[BrokenStep].Physics == PHYS_RigidBody)
        {
            StaticMeshComponent.WakeRigidBody();
        }
    }
    
    
    function BreakLastApart(Controller EventInstigator)
    {
        local KActorSpawnable SpawnedActor;
        
        SetPhysics(PHYS_None);
        SetCollision(false,false);
        if (CollisionComponent != None)
        {
            CollisionComponent.SetBlockRigidBody(false);
        }
        SetTimer(0.1, false, 'HideAndDestroy');
        TriggerEventClass(class'SeqEvent_Destroyed',EventInstigator);
        
        if (BreakableSteps[CurrentBreakableStep].BreakSound != None)
        {
            PlaySound(BreakableSteps[CurrentBreakableStep].BreakSound, true,,, CollisionComponent.Bounds.Origin);
        }
        
        if (BreakableSteps[CurrentBreakableStep].BreakMesh != None)
        {
            SpawnedActor = spawn(class'KActorSpawnable',,,Location, Rotation);
            if (SpawnedActor != none)
            {
                SpawnedActor.StaticMeshComponent.SetStaticMesh(BreakableSteps[CurrentBreakableStep].BreakMesh);
                SpawnedActor.SetPhysics(BreakableSteps[CurrentBreakableStep].Physics);
                if (BreakableSteps[CurrentBreakableStep].Physics == PHYS_RigidBody)
                {
                    SpawnedActor.StaticMeshComponent.WakeRigidBody();
                }
            }
        }
    }
    
    function HideAndDestroy()
    {
        StaticMeshComponent.SetHidden(true);
        Destroy();
    }
    
    event Destroyed()
    {
        Super.Destroyed();
    }
    
    defaultproperties
    {
        CollisionType = COLLIDE_BlockAll
        bNoDelete = true
        bProjTarget = true
        CurrentBreakableStep = 0
    }
    Actor Factory for the Above Code.
    Code:
    // Actor Factory for Custom Breakable Actor Class
    
    class DarkJourneyBreakableActorFactory extends ActorFactoryRigidBody;
    
    defaultproperties
    {
        MenuName="Add Dark Journey Breakable Actor"
        NewActorClass=class'DarkJourney.DarkJourneyBreakableActor'
        CollisionType=COLLIDE_BlockAll
    }

    #2
    Hi there!

    It's not clear exactly what you want the particle system to do.

    Do you want to be able to spawn them attach them to the current state of your many-state object?

    are you trying to spawn different particle systems based on state of object?

    Till you answer those questions:

    I have four tutorials on implementing particle systems via unrealscript, have a look

    I suggest going through the walkthrough tutorial as in that tutorial I show you how to
    1. spawn a particle system through code
    2. attach the particle system to an actor
    3. have the particle system keep moving, staying in its position relative to the actor you attached it to.


    ~~~ Particle System Effects and Emitters ~~~

    Walkthrough: How to Spawn a Mesh ParticleSystem "Energy Shield" that Appears when Actor is Shot At
    Walkthrough, giving your enemy creatures a mesh ParticleSystem energy shield

    Spawn Explosion Particle Effects!
    Spawn Particle Effect Explosion That Goes Off Once

    How To Fix: Particles Disappear When Camera Not Facing Emitter
    How to ensure your physx or other particle system effects do not disappear

    How to Make an Actor Class that has a Particle Emitter Attached at Spawning Time
    Spawn Actor class with Particle System Emitter Attached



    Rama

    Comment


      #3
      Yes, I want it so each damage state can have its own particle system, so an object would smoke when damaged(State 2), then after being damaged even more would catch fire(State 3), and then finally explode(State 4). Yes it needs to be able to stay with the actor that it is attached to, that way if the actor moves then the particle system will move with it. (State 1) is the mesh undamaged just sitting normally in the environment.

      Comment


        #4
        well that's easy enough

        review my tutorials on attaching particle system to your destructible states actor

        annnnnd

        the magic code:

        to make 1 emitter disappear so that the new emitter you spawn is the only visible one (as the states change)

        Code:
        local particleSystemComponent ps;
        
        //ps = WorldInfo.MyEmitterPool.SpawnEmitter(... //see my tutorials
        
        ps.SetHidden(true);
        ps.DeactivateSystem();

        then re-enable the emitter you disabled when you want to show the previous state again
        Code:
        ps.SetHidden(false);
        ps.ActivateSystem(true);

        Comment

        Working...
        X