Trying to add a material custom output node

Hello everyone

I’m a student who is trying to use the unreal engine source code to make a custom celshading model. I’ was following the guide of 0ne3y3 (New shading models and changing the GBuffer | Community tutorial)

He uses 5.1 while I’m using the release branch version which is 5.4 I think. I recreated everything he did and was able to build the engine successfully.

Now the issue is making my custom output node. I made a new class that inherits from UMaterialExpressionCustomOutput and added the implementation to the MaterialExpressions.cpp file

After testing out the code in the material editor when I add the node the project freezes and I can’t move or even close the project without using task manager.

I need help adding this custom output node and I can’t seem to find any resources relating to my problem so as a last resort I came here.

I had this issue with Unreal freezing as well. I found a way to fix it but my unreal version is 5.6 something, so it is not guaranteed to work for you.

How to find the issue:
Start the program in debug mode,
Do the thing until unreal freeze,
Let it run a little then press pause in visual studio.

After some stepping then you will see the program is doing this endlessly
for (FExpressionInputIterator It{ this }; It; ++It)
{
DoMaterialAttributeReorder(It.Input, UEVer, RenderVer, UE5Ver);
}

By stepping in FExpressionInputIterator, you will see that the GetInput() function is being called. It hints that GetInput() function might be problematic and it is causing infinite loop here.

The fix:
By viewing some other GetInput Function in the MaterialExpressionCelShadingOutput, I changed the function to this.
FExpressionInput* UMaterialExpressionCelShadingOutput::GetInput(int32 InputIndex)
{
return InputIndex == 0 ? &Input : nullptr;
}
Recompile then it is fixed on my side.