c++ FScalarMaterialInput to opacity?

Hi all, I am trying to edit material connections from c++, in-editor, from a plugin.

How should I connect Textures to the Material slots?

I have, for example:

UTexture *Tex = LoadObject<UTexture>(NULL, *Itr2->GetName());

FScalarMaterialInput matAlpha;

Material->Opacity = (matAlpha);

How can I link the ‘Tex’ to the ‘matAlpha’ and therefore to the Opacity slot of ‘Material’?


You can’t, FScalarMaterialInput and UTexture’s are two completely different types. You’ll have to look at the way the TextureSampler node actually dissects the information from the textures. You can actually only send one channel of the texture to the Scalar Input, or convert the Vector output into a Scalar by converting it to grayscale essentially, which is what the Material editor does.

Ok, that makes sense. Thanks for your reply.
So I find my file in the content browser with an iterator and name flag.

I have it as a Texture2D, or I can convert it to a UTexture. I only need the alpha channel, as I am connecting it to opacity.

Is there any docs on how I would convert it to Scalar?

Afraid not, usually this kind of thing is done in a Dynamic Material Instance (which are for runtime). Those allow you to change parameters on the fly pretty easily.

I assume your writing a plug-in for the Editor to help with material creation or something, not something that’s designed to work in-game? If so you’ll have to figure most of this out for yourself by looking at Engine code.

Exactly, plugin that runs in editor and connects imported textures to material slots.
Gaaargh, I was afraid you would say that. I will trawl through the editor code. Any last tips on where to start? :slight_smile:

I honestly am not sure, best place to start would probably be to look at the Material Editor itself!

Bear in mind, you can right-click a bunch of imported textures and hit ‘Create Material’ and they’ll be dropped into the Material already!

Ok I will trawl through the code. Thanks for your help!