I’ll quickly try to detail out where I am and what’s going wrong with my plan. I’m a noob to BluePrints, but have been making game assets for years, but this is all very new to me.
I have castle walls that get destroyed on collision with a cannon ball. They literally disappear after a delay of 3 seconds.
I wanted this to be more graceful, so set about using BluePrints to switch materials to a fading one and control the fading of each hit object. This is using a ‘Material Parameter Collection’ with just a scalar value in it.
On mesh hit, I’m switching the material to my fade material and then that causes the mesh to fade out.
I’m then using a timeline node inside the castle wall blueprint, to kick off the fading upon collision.
The Problem:
The issue comes when the cannon deflects off another surface, and hits another wall section. The fading animation restarts for all already destroyed wall pieces that haven’t faded away yet. (I see why, it’s because there is one material doing the fading of the mesh, and each hit just causes the single material to restart its animation.)
BUT…
What would be a decent alternative to doing it the way I’ve done it?
Can I instance a material per collision, and then remove it when the actor has been destroyed?
Why switch materials at runtime?
just make a function inside the wall material that allows for fading. That way each instance has its own parameter and you won’t have issues like the ones you got.
The wall BP (you probably already have them as BPs) can use a dynamic material instance.
Alternatively - if you aren’t using BPs - you can get the cannonball to swap the mesh out with a different one thats set to fade. You just can’t save its status unless you do some array magic to keep track of what’s changed in your level save/load.
with the BPs and the instancing this may be easier (but you’d still need to code for it).
So, I’m using a different material because I thought it might be better to have one non-translucent one, and another that can fade out. Just for optimisation-sake really.
Not sure if that’s the right way to go really.
Call me a thicko, but how do I create a function inside of my material that would be linked to my wall blueprint? A link to docs would be fine!
I think I found another post that sums up my problem.
It was trying to get footprint decals to fade away with each footstep. Unfortunately, each footstep fades at the same timing. You’d need a new texture for each footstep, and keep track of when they were laid, in order to have them fade out in sequence.
(Although I’d probably cheat it with a distance from main character and fade them out… But it doesn’t help my issues above unfortunately.)
Will ask the guys at work tomorrow, see if they have ideas.
Also, will post my nodal setup in case it helps.
Footsteps are one thing. Place them with Niagara and control them that way.
Walls are another.
Create a material function. Add an input as material attributes. Break the material attributes. Play with the settings - to create the fade however you want/what fits gameplay.
output to material attributes.
In the material, make material attributes with the wall stuff. Put the function in and connect it. Connect it to the output (after checking the box to use material attributes in the material settings).
Then you just create a dynamic material instance, and from it. You can adjust the scalar parameter that controls the fade over time.
as far as material process you could also build the fade into the material using time node, but this is prone to reset, so stick to managing it with a timeline in the blueprint. At least you are sure it can only ever trigger once per wall.
Don’t forget that you also need to remove collision.