Making an enemy flash red when hit

Hey, I was wondering if anyone knows how I can make an object flash a specific colour. Specifically, I’m trying to make an enemy flash red when they’ve taken damage, as a visual cue to the player that their attack is working, like :

2sltvio2gko71

I’ve tried looking online for tutorials but all I can find are tutorials on how to make a material pulsate in a particular colour. That’s kinda along the lines on what I’m trying to achieve but not quite the same thing, I only want the enemy to flash once and that’s it.

Thanks in advance!

2 Likes

Hi @HungryMoogle!

That is definitely possible. In fact, Unreal has a great Live Training that actually deals with effects and changing materials with blueprints on their YouTube page!

Here is the link to that Live Training:
Controlling Effects with Blueprints | Live Training | Unreal Engine

While the video adds a particle effect and “dissolves” the material of a sphere, the same principles apply.

2 Likes

The appreciate the response but, ummm, seems a bit much. Isn’t there any simpler tutorials? My preferred method of working on my game so far has been to work my way up from doing simple, easy-to-do tasks and as I gain more knowledge & confidence in my abilities, gradually move up to more complex tasks. Meanwhile, that tutorial you’ve posted feels like I’m taking a course on constructing a medieval cathedral in order to learn how to build a sand castle.

a simple implmentation is only a couple steps like :

On event hit/damage, get the hit actor, get its dynamic material instance, turn on emissive parameter for a time, turn it back off.

If you look on youtube for “unreal dynamic material instance”, you’ll have plenty of beginner tutorials showing you similar ideas.

6 Likes

So looking into it a bit more, evidently you can use a timeline to change the colour of an object as mentioned here and here.


I tried playing around with the colour timeline to see if I could get to work for my purposes but so far I haven’t had any luck at all in figuring out how it works.

1 Like

I have a question about Dynamic Material Instance. Doesn’t it only affect one material instance? At least that’s the impression that I get from watching videos, which I feel like is going to be a bit of issue with enemies that are made up of multiple materials & other components.

The basic ‘Goomba’-type enemy for my game, for example, has separate materials from it’s body for it’s eyes & mouth, and it’s arms and legs are separate from the main body as well, in addition to the hat it wears on it’s head.

It just seems to me that making all the materials flash red separately is going to be a major time-consuming headache to implement. Isn’t there a way to just the entire object flash a colour instead of one material?

Try using custom Stencils:

My quick setup:

  1. The PostProcessVolume: you only need to set a single material in the PPV and it will only affect those components that have ticked Render CustomDepth Pass.

  2. The material is hard to explain :sweat:, best if you watch the video above:

  3. The idea is to set it up so that it can be used on any actor. For I created an actor component that I can add to any actor that can recieve damage and it takes care of the rest:


Result:
CustomStencil


Hope it helps

10 Likes

I think @pezzott1 offered the most modular and non-destructive solution, but I’ll mention one other possible solution which probably isn’t a good idea but, depending on project specifics you never know:

that would be to have your flashing behavior on a master material and then your characters material instances can derive from that. It probably wouldn’t work in many cases but it could be an option in some.

1 Like

Thanks for !

I’ve followed all of your instructions & have constructed the material, as well as the actor component blueprint but I have one little issue. How I do actually invoke the hit flash within the enemy’s blueprint? :sweat:

Just apply damage to the actor and it should work.

Unfortunately, its still not working.

I have a Apply Damage node attached to the player character’s basic attack.

And I tried attaching the actor component to the both parent enemy base blueprint and a parented individual enemy blueprint, both to no avail.

I think the blueprints for the material & actor component are both set up correctly but maybe I’m wrong.

Material blueprint:

Actor component blueprint:

1 Like

Is set to SkeletalMesh?
image

No, but I made the change after you suggested it and it still doesn’t work. :disappointed:
component_class_to_search

To have a better idea:

  1. On the enemy actor add a print node after the take any damage event.
  2. On the component Add a print node in the start flash event.

Do they get called when the actor receives damage?

Yeah, both messages appear when the enemy is damaged.

Good. So it has to do with the material.

Did you setup the material in the PPV? Is unbound ticked?

I checked and the material is indeed setup in the Post Processing Volume.

post_process_materials

I assume that ‘unbound ticked’ refers to ‘Infinite Extend (Unbound)’ in the Post Process Volume Settings, in which case, yes, it is checked.

post_process_volume_settings

1 Like

Sory I missed earlier :upside_down_face:: set your Material domain to Post Process.

Okay, I switched it over but it’s still not working.

I have a question, I’m a supposed to be using the Apply Damage node or the Start Flash one? Or does it make a difference at all?

I would have tried using Start Flash node but I don’t know what the Target is supposed to be hooked up to.

The idea is to have the component bind to take any damage so every time the actor receives damage it executes the start flash.

For your image above, the actor that should flash is the one that enters BatCollision.

If you want we can get on Discord and go over it all to find your issue.