Q2. The Material code that will be connected to the Static SWITCH parameter, adds 40 Instructions (it’s rain drip code). Thus my idea was to turn off these Instructions/branch on the Character Mat/Mesh when not needed, by using the Bool/Switch.
But if the 40 Instructions are activated while in the game (not pre compiled), then will this force a noticeable Compiling delay?
If yes, should I not use the on/off Switch, and instead set the effect to 0 = a Scalar Paramater (rain drip does not move and thus does not show - but the 40 Instructions are still active)? Thank you.
I don’t think you can (it doesn’t make sense that it’s called “param” if you can’t change it, but there could be some runtime limitations or performance reasons), anyway you can set the On/Off scalar value to 1 if you do something like this:
The StaticSwitch expression works like a StaticSwitchParameter, except that it only implements the switch and does not create a parameter.
So, you need a StaticSwitchParameter to be able to set something up, and then you can use this switch to choose one value or the other based on an input value such as that parameter.
You might want to set these up as material instances, so you can create one instance with it “on” and one with it “off”
Thanks a lot for your statement *and that picture!
(In UE4, the AB node doesnt show the B value on screen, so I didnt understand it. But yours shows A compares to B = 1, so I understand better.)
Do you have an opinion about Q2, if I should keep the 40 instructions on (by cutting out the On/off True/false) - so that I dont get a compile lag hit in game (if suddenly turned on 40)?
Maybe thats why there is no node to turn these Mat Switches on/off at runtime?
Thank you, interesting. Im looking for the most performant method to turn a heavy effect Material (function) on off. Ive already had to increase my Texture cache pool (and my game will be Texture intensive).
Thus should I make 2 versions of the MI, with the switch on (rain effect), another with it off, and instead merely change the MI that my character uses in game as needed? (I can make a DMI of an MI, yet still change the MI and make it into the new DMI, correct?)
Or should I use the above suggestion, and have on/off using the same MI > made into a DMI? Thank you.
I think my answer is more a workaround than a solution, you should probably do a performance check and see if it performs better with the “if” or maybe assigning an existing material instance to your mesh (instead of setting the parameter), probably @jwatte knows this argument much better than I do and might enlighten the both of us
Method 1 (fails?):
Thanks for the pic. So I tried this, I can setup the Bool in Mat code. But there is no node in Blueprint (editor) to change the Mat Bool?
I can get around the failure by using MIs as you said (one MI has the Bool already on, the other has it off). But it may be best for me to not use named MIs, since I’ll have multiple character MIs - harder to code in at the BP.
[PS thanks for the edit update. But your first post said something about a Lerp. Can you edit that back in? I’d like to learn how to ramp up/blend on - another Param/Mat effect - from Char BP. Ty]
Method 2 (works but +4 instructions):
So I made an emulated (fake) switch in Mat code using IF node and a Scalar Param.
(Note for UE4 users: the B is set to 1.)
Then in Char BP, I turn on the ‘switch’ by setting the Scalar that it represents to 0/1 = off/on.
This seems to work in game. But the first time I ran it in test Game, I did get a message that Shaders were compiling. It seems like it may do that once, the first time I load the engine/game?
Thanks everyone for the replies/pics. I’ll keep testing then select the best answer
The whole point of a static node is that you set it in the material instance, not as a material parameter. This optimizes the shader count and shader memory usage.
If you need to change the value at runtime, then you should use a regular parameter, not a static parameter.
Using lerp is pretty easy. Put in two colors (or values, or vectors) and a scalar between 0 and 1. At 0, you get A. At 1 you get B. At 0.5, you get the mid point.
Btw: That parameter at the bottom is a “scalar parameter.” Each color is a “constant vector3.”
To get more insight into materials, download some free content packs from the Marketplace and pick apart the materials that they come with.
It’s not “better,” it’s “different.”
If you want the choice to be “either/or” then if is better.
If you want the ability to blend between the choices, “lerp” is better.
Thanks everyone for the fast answers and pics yesterday. @Ares9323 answered my topic Question - best way to make a [fake] Bool in Mat code, that I can control from Character BP.
(since there appears to be no Mat-Bool related node in Blueprint code?) So i’ll mark that as the solution for others to search.
Everyone else note that this is a hard on/off (acts as a Bool) - no smooth transition between the effect change.
But @Ares9323’s question and @jwatte’s reply is interesting. I see it is best for what I want instead - a smooth blend from my default Material to the Rain effect.