Help with dynamic material/font for ammo count

Hey everyone, i was wondering if anyone could help with this.
we currently have a fps game where the player checks their current ammo count in various ways by interacting with their weapon.

for instance pulling back the slide or seeing the bullet number on the bullet or looking on the side of the gun for a screen (similar to halo)

the issue is trying to get this to update whilst not using a simple texture swap via, some of our weapons have 60+ ammo and this amount of textures seems absurd to keep swapping to and from. Maybe im thinking about this all the wrong way and there’s a much simpler method to do this. something like a font/text or hud that can be controlled by variable in blueprint.
I really hope I’ve made sense trying to explain this, please ask if there’s any confusion.
Been ripping my hair out the last couple of days trying to get a solution for this haha
hope someone can help :slight_smile:
many thanks

Really dont know the best solution. Flipbook, text, texture swap? D:

I already answered your question in the forum where you asked it.
Generate a 8x8 cell texture (just a big square texture that you slice in 64 smaller squares)
Paint the numbers 1 … 64 in the cells.
Select one cell for your ammo using UV scaling and offset.

By the way: You probably want specific geometry only for the numbers that covers that area snugly, and uses UV values from 0.02 to 0.98, for best use of texture space. Cut out and duplicate the few triangles that make up the number, and offset them a fraction of a millimeter to avoid Z fighting, or apply as a decal.

So, assuming the area that needs to display the numbers uses this texture, and is mapped in the 0 … 1 range with some margin, then the UV you need for a particular number is:

Uused = (Uin + (Count - 1) % 8) * 0.125;
Vused = (Vin + ((Count - 1) / 8) % 8) * 0.125;

If you do this in blueprint, then “modulo” is the “%” operator.

“Uused” is the U value that actually goes to the texture sampler; “Uin” is the texture coordinate into the shader. “Count” is the value you want, from 1 to 64.

Also: the texture you posted in the forums makes very inefficient use of available texture space. For best performance, you want to use as much of each texture as possible.

There’s a built-in blueprint function to do this: Texturing | Unreal Engine Documentation
Here’s a blueprint that uses it for 1 … 4; you want to make a texture of size 1 … 64 (8x8) for your use case and set the side count to 8.

You did?! apologies.
Thanks btw i shall try this and let you know how i get on. seems a little more complex than i thought but thank you very much for the advice

Are there any examples that show what your explaining in some form? It just seems a little confusing. Sorry :frowning:

Im also using Blueprint

I added an example with screen shot. Please accept the answer if it helps.
The reason it subtracts 1 from the count is that I assume you want 1 … 64 .If you want 0 … 63, then you don’t need to do that.

Thank you very much for the help, i appreciate it (answer accepted :))
not quite sure what you meant with the UV’s and cutting out O.o
but my bullet has separate material ID’s and UV’s.
im just wondering how universal i can make this for all of my other weapons.
Ideally i’d like this to appear just above the original texture of the bullet.

Many Thanks
:slight_smile:

Easiest is probably to define a specific material ID for only the bullet counter area, and UV map that between 0 and 1 (filling the entire square in the UV Unwrap editor.)
You can map the “un-counted” material to this square, and then add the sub-graph above to the Emissive output of that material. You will need to make the material dynamic and update the “Count” property of the material. When the value into “Frame” is 0, the top-left square is shown. Whether that is “1” or “0” or a picture of a cat depends on your game :slight_smile: