Dissolve Dying Effect

Currently my enemies are just disappearing.  ShooterTutorial will be ported to Mobile some day and I want to be sure that my ragdols can be turned off as soon as possible. That’s why I will add nice dissolve effect. Which should be:

  • Component based – can be attached to any Skel/Static mesh actor,
  • Using Material Layers – this way I will get original material,

This Tutorial has been created using Unreal Engine 4.10
Make sure you are working on the same version of the engine.

Creating Dissolve Material Function

There’s a great tutorial about dissolve over here. You can read it before moving forward.

Create new Material Function named LayerDissolve and recreate this material:

dissolvefunction

It calculates opacity mask based on texture and dissolveammount scalar value. Next it’s adding emissive depending on EmissilveBlendSize value.

Make sure DissolveAmmount is set to 0 by default!

Adding Material Function

After creating material function it need to be added to every enemy that you want to see dissolve effect.

I will use Future Soldier as It have custom emissive. Open FutureSoldier material and add LayerDissolve:

addingfunctiontomaterial

Find MaterialFunctionCall node, and then select LayerDissolve in Details panel.

Next break out material attributes:

breakmaterialattributes

So we can get Emissive and Opacity Mask from it.

Make sure material blend mode is Masked. It need to have Opacity Mask attribute. Now just add Soldier custom emissive to dissolve emissive and do the same with opacity.

futuresoldierfinalmaterial

And that’s it. You have final material that can support dissolve. The same thing need to be done to every enemy material that you are using.

Preparing Dissolve Component

Now we can actually run the dissolve.

Dissolve Curve

First create new Float Curve named DissolveCurve:

floatcurve

Here’s the curve:

curve

You will mess with the values here later – when you will see dissolve effect running.

Dissolve Component

Now create new Actor Component blueprint named DissolveComponent, open it and add these variables:

Var Name Var Type Description
DissolveMaterials Material Instance Dynamic Array This will store all materials that should be updated by dissolve.
isDoingDissolve bool Is updating dissolve.
CurrentDissolveAmmount float Holds current dissolve ammount.
Curve Float Curve Reference Should point to early created DissolveCurve.
AccumulatedTime float Holds accumulated time. It will be used to stop dissolve when it gets proper value.
DissolveColor Linear Color Should be Editable. This will be passed to Material to change the color.

Now open your event graph and add new custom events.

GetStaticMeshes:

GetStaticMeshes

It basically iterate all static meshes then getting all materials and change them to Dynamic Material which can use parameters. (our Dissolve function have parameters that we want to change) Normal materials can’t use parameters that’s why you need to create Dynamic Material.

GetSkelMeshes:

GetSkelMeshes

This event is exactly the same as previous but it use Skeletal Mesh Components instead.

SetColor:

SetColor

This basically change DissolveColor parameter on each dynamic material.

BeginPlay:

beginplay

I’m using Begin Play to populate DissolveMaterials and change the color, as I want to do this only one time on loading.

ResetDissolve:

ResetDissolve

This event basically resets everything so dissolve can be fired again.

Tick:

tick

Tick is updating DissolveAmmount on each material. It won’t be fired if isDoingDissolve is false.

DoDissolve:

DoDissolve

It will enable dissolve.

Enabling / Disabling Dissolve

Now it’s time to use DissolveComponent and find a place to enable and disable dissolve.

I will use BP_BaseEnemy to enable / disable dissolve. Open BP_BaseEnemy and add DissolveComponent in Components View. Then find Die function and call DoDissilve on DissolveComponent:

DoDissolveInDieFunction

It will start dissolve effect when enemy will die.

Now the best place to reset dissolve will be in Event Reset Enemy interface event.

ResetDissolveInResetEnemy

Final Result:

Creating ShooterTutorial takes a lot of my free time.
donateIf you want you can help me out! I will use your donation to buy better assets packs and you will be added to Credits /Backers page as well. Implementing game is taking time but writing about it is taking much more effort!

 

4 thoughts on “Dissolve Dying Effect

  1. Hello,

    I completed the tutorial step by step but it is not working for me. Are you able to tutor over skype? Please let me know

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.