0
\$\begingroup\$

Is it possible to access a node from the Material Editor from a C++ script?

I'd like to be able to change the value of 'Mulitply' from a script.

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ It sounds to me like you might want to make a Material Parameter out of your multiplication coefficient. \$\endgroup\$ Commented Aug 27, 2021 at 20:23
  • \$\begingroup\$ Thank you! I will look right into it. \$\endgroup\$ Commented Aug 27, 2021 at 20:25

1 Answer 1

0
\$\begingroup\$

In your Material, create a Scalar Parameter (hold 1 on the material grid and left click), name it and plug it in to your multiply node.

In your C++ header, create an instance variable and set it as a UPROPERTY so it doesn't get garbage collected.

UPROPERTY()
UMaterialInstanceDynamic* DynMat;

In your C++ constructor, set the dynamic material instance from the existing material on your mesh then set it to your mesh.

DynMat = UMaterialInstanceDynamic::Create(YOURMESHNAME->GetMaterial(0), this);
YOURMESHNAME->SetMaterial(0, DynMat)

The 0 in the get and set refer to which Element of the mesh the material is set to. If 0 is the back of the card and 1 is the front, change the code accordingly.

From here, you can use the DynMat reference to change your parameter values as follows.

MI->SetScalarParameterValue(TEXT("YourMultiplierName"), NewFloatValue);

YourMultiplierName must match exactly what you put in for the name of the parameter in the material grid, otherwise this won't work.

\$\endgroup\$
1
  • \$\begingroup\$ thanks mate. I did already get it working due to DMGregory's help, but nice to have it all typed up with example. I would upvote but I don't have enough rep \$\endgroup\$ Commented Aug 31, 2021 at 19:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.