Accessing Material Custom Expression Inputs by their index instead of their name

Hey, I am not sure if this is even possible and I couln’t manage to find any answers to my question.

Is it possible to access the input array of the Custom node directly, instead of using the names of the inputs?

Like ‘Index[0]’ instead of ‘Color1’?

I want to add new inputs in the future and want to avoid manually adding them (by their name) each time.

Thanks in advance! :saluting_face:

I think you could try using “Additional Defines” to define an array of values (colors) that can be used in your code. For example, here’s something you could try:
First of all, you create your inputs [Color1, Color2, …],


Then you add one “Additional Define” COLORS and put all your input names to the “Define Value”, like this:

Then you can use COLORS in your code like this:

Which should just mix the colors.
This way you only have to duplicate the name of each input, but you don’t have to change the code itself. I don’t think this is a perfect solution, but it’s basically the best you can do. Although you could just as easily avoid using “Additional Definitions” and directly hardcode the input names in the code, e.g.

So you have to use input names anyway. Accessing the input array directly from HLSL code is simply not possible.

While you could certainly write your own Custom C++ material expression to create a node that loops through the inputs to make it work exactly the way you want, that’s much more complicated and requires the skill of writing your own C++ material expression nodes.