Material Node getting Texture2D in not compatible with Float

I’m trying to use the following to build my Material Node in c++:

https://dev.epicgames.com/documentation/en\-us/unreal\-engine/custom\-material\-expressions\-in\-unreal\-engine?application\_version\=5\.4

But I’m getting the following error: Texture2D in not compatible with Float

And I can’t connect the texture node. Please also see attached error.

Attached is the code.

Thank you.

Hanna

Hello there,

The reason the custom expression believes everything is a float is because the default return value of UMaterialExpression::GetInputType is MCT_Float1.

What you are missing is an override on that function that specifies the types of the inputs you are using. I’ve provided an example below.

uint32 UFSCS_TextureBlur::GetInputType(int32 InputIndex) { if (InputIndex == 0) { return MCT_Texture2D; } return MCT_Float1; }I’ve chosen Texture2D as the sample type won’t work on all texture types.

As an aside, the return type is CMOT_Float4 but blur is a float3. There isn’t an automatic promotion from float3 to float4, so this doesn’t compile without that amendment.

Best regards,

Chris

Thank you for you help. That was it.

Thank you.

Hanna

You’re very welcome.

If you have any questions, please feel free to ask. Otherwise, would you mind if I close out this case for now?

Best regards,

Chris

You can close.

Thank you for your help.

Hanna

Will do.

If you have any other questions, please feel free ask.

Best regards,

Chris