I was curious if there is a way to have one shader that can pick a random texture from an array, or if i have to just make a bunch of material instances with each one set to a different texture?
I think you might be looking for a texture atlas
I don’t remember seeing an array texture in shader file, but I can imagine what you mean done by additional script to the shader, have you tried that?
never used them. are there any good resources i could use to learn how?
No idea how to do that. would appreciate some pointers
Easiest way is to subdivide your texture like you would for a flipbook then select the texture you need like you select a random frame of a flipbook.
Only real downsides are that it obviously loads the entire texture even if you don’t use the whole thing, and tiling might not work perfectly
simply by making 2 variable :
textures array and material
with a function that generate a random number that doesn’t exceed the length of the textures array
and then setting this material texture property or something to this randomized texture
I’m not sure exactly how the communication between scripts and material works in unreal (I guess that what you are using)
I don’t know when the functionality was added but at least from UE5.2, you can set the SubUV Animation Mode in the Sub UV Animation module in Niagara to use Random instead of Linear, without any material side setup. You just give it an Atlas texture, and it will pick one frame. This doesn’t make the loading cost mentioned cheaper, but it’s easy to toggle on.
Note that there is no subUV animation for decals, so if you want to have a blood decal, then you do need to go back and do the material side setup to shift your UVs to pick the frame you want. This video was good for helping me getting started on it:
https://www.youtube.com/watch?v=WmM19H8Uwu8&t=147s