How do I know when an input node is assigned in a custom UMaterialExpression?

I have created multiple new classes that derive from UMaterialExpression: New Texture, and Crop Texture.

Each of these classes have a UTexture2D within them.

The “New Texture” material expression has two UExpressionOutputs: “Texture” and “RGBA”.
It also has the properties: clear colour, width, and height.

“Crop Texture” has two UExpressionOutputs: “Texture” and "RGBA, and one UExpressionInput: “Texture”.
This also has the properties: Left, Top, Right, Bottom.

When I connect the “texture” output from “New Texture” to the “Texture” input on “Crop Texture”, I will have to create a new UTexture2D which is the same width and height as the passed in one, and copy the pixels over to the new texture. plus I will also change the: Left, Top, Right, and Bottom, values to be the same as the passed in texture.

The issue is that there is no way to tell that the UExpressionInput has been connected to a UExpressionOutput.

Usually when you change a property on a UMaterialExpression, the virtual method “PostEditChangeProperty” (from UObject) is triggered and you know which property has changed.

PostEditChangeProperty is never triggered when the UExpressionInput is set, this is because the UExpressionInput doesn’t change, but instead an internal pointer to the connected UMaterialExpression is set.

In the UMaterialExpression, there are only two methods that trigger when a UExpressionInput is assigned to: Compile, and Modify.

Modify cannot be used as a solution to this as the UExpressionInput.Expression is assigned after this method is triggered.

Compile cannot be used, as the material compiler gets the texture from the UMaterialExpression just after construction and if the internal texture changes, and if you change the texture in the compile method, you cant reference the new one in the compiler, as the material compiler is expecting the previous texture that has now been destroyed, which causes a blow up.

I can make a change to Unreal’s engines code to cause a property change in the UMaterialExpression when an input is assigned-to/unassigned-from, but I plan on making this as a plugin for a none modified version of unreal.

Any suggestion on how to know when my input node is assigned to?

Alternatively, if i could resize the internal texture rather than recreating it, this would potentially resolve my problem, but i cannot seem to find any way to do this either.