# How to add a hit count (health points) to individual instances?

**URL:** <https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [April 30, 2021, 3:43am UTC](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176 "2021-04-30T03:43:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rangozo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rangozo](https://forums.unrealengine.com/u/Rangozo)\
**Post date:** [April 30, 2021, 3:43am UTC](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/1 "2021-04-30T03:43:49Z")

</div>

Hi everyone.  
In my project I try to destroy bricks (Instances) after a certain number of hits. For now I’m able to destroy each whats a clever way to add points of health to an instance?

If you have any question on what i have set up rn i will be glad to answer.  
Sorry for weird english also :}

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 30, 2021, 6:49am UTC](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/2 "2021-04-30T06:49:36Z")

</div>

> [@Rangozo](#):
>
> whats a clever way to add points of health to an instance

The name of the game is Custom Primitive Data (check docs at the bottom).

## The material for a brick:

- each instance stores a float which is used to Lerp between 2 colours (to visualise hits remaining)
- this can (and probably should) get prettified

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/6/8685f1fc9f49e50426cef4d21d23ec1eb71a6467.jpeg)

## Making a brick wall:

- create a bunch of instances and store their data in an `int | int` Map
- instead of an integer, you could have a struct and hold all kind of data here; perhaps this brick is worth some coins, or explodes when destroyed and takes their neighbours with it (I’m thinking you’re making an Arkanoid but you might be about to Minecraft 2.0)
- we need to feed the material a 0-1 Alpha range for the Lerp so we math it out
- if you’re creating thousands+ of those, it might be worth looking into how Dirty State works

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/d/dd1f88486624586522241074257fe944220ca4ed.jpeg)

## Brick getting hit:

- a Custom Event pipes in an index of the hit instance
- we find its data in the Map and adjust it, removing 1 hit from Remaining, and shoving the value back into the Map
- we update the material in a very similar fashion as before
- we need to get rid of an Instance if no more Hits remain…
- …if you were to _remove_ an instance of an Instanced Static Mesh, the indexes would get jumbled and we’d need to rebuild the Map; so we don’t remove the Instance, we move it below ground instead (or where the player cannot interact with / see it). This way the indices remain intact.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/1/a128e352f2736a4b92331251d106ef2f52c24ee5.jpeg)

## Hitting bricks:

- this detects what’s under the cursor and calls the above-mentioned Custom Event, providing the hit instance index
- you’ll probably have a more elaborate interaction method

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/f/4fe7dd29f0cc134f05b35ac0aae243751448c249.jpeg)

## The end result

So, 1 material and 1 Instanced Static Mesh, no iteration, no ticking. So this should be good for all kind of fun stuff:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/3/837eef323de64fd8d274d35caf8e9f777f2ac74e.jpeg)

* * *

[https://docs.unrealengine.com/en-US/RenderingAndGraphics/Materials/CustomPrimitiveData/index.html](https://docs.unrealengine.com/en-US/RenderingAndGraphics/Materials/CustomPrimitiveData/index.html)

---

<div class="post-metadata">

**Author:** ![Rangozo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rangozo](https://forums.unrealengine.com/u/Rangozo)\
**Post date:** [May 8, 2021, 11:55pm UTC](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/3 "2021-05-08T23:55:32Z")

</div>

Wow Thank you so much man i will try it out !

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 9, 2021, 10:52am UTC](https://forums.unrealengine.com/t/how-to-add-a-hit-count-health-points-to-individual-instances/227176/4 "2021-05-09T10:52:17Z")

</div>

Do tell how it goes. Technically you don’t need Custom Primitive Data for this and simply keep it all in a map only. But you did ask for _clever_ and it’s not a bad use case scenario for the feature.
