Change material static mesh

Hello.

I have seen some topics already concerning this matter, but none of those seem to work for me.

I have a blueprint with an aircraft (BP_Aircraft), consisting of several static meshes. I also have a widget with some buttons. By the click of a certain button (TestButton) on this widget, I want to change the material of one of those static meshes (Cabin Main) in the blueprint BP_Aircraft to a fixed material that I have (Glass) and change it back to its ‘original’ material (Metal) when clicking the same button. What I have now is this for only changing it to Glass:

With some topic discussions, this should work (since I have set the material and the actor class). Some other topics state that I need to create a dynamic material instance and then attach a material variable to that, but for me that would be strange I think since I’ve fixed the material to Glass. In any case: nothing works for me and I don’t get errors, so what I have is not wrong but it does miss something. I just have no idea what I’m missing.

I hope anyone can help.

Create an event in BP_AirCraft … Update Fuselage

Update FuselageSet Material (static mesh component)

In the Widget get a reference to the BP_Aircraft instance and call the Update Fuselage event.


Semantics wise you should not be using Get all Actors of Class for this. You should have a direct reference to the specific instance before clicking the button. How is dependent on what class is implementing the UI and your overall setup.

Hello, I tried this but I get a lot of errors:

I tried this, but I get some errors.

In the aircraft blueprint I have:

Then I have this in the widget:

Where Aircraft is:

image

When I run it, nothing happens and I get:

You have to set the value of aircraft. It’s currently empty.

Can you eloborate on this? I’m new to Unreal Engine and try to learn it.

What I thought was to create a variable in the Level Blueprint named “Aircraft”, referencing to the BP Aircraft:

image

But I think I need to do more. Could you please explain what exactly? And how?

I think the problem is somewhere here:

image

But no idea how to get from None to something useful.

The variable is just a placeholder. You need to get a reference to the specific instance that’s loaded in the game world. For example Get all actors of class returns references to all instances of that class that are loaded into the game world. If there are none the returned array would be empty. If you have 10, then all 10 are randomly listed in the array.

I have no idea what your game is about or any of its design so I can’t tell you how to get the specific reference.

If I had an actor in the game I could modify I would probably start by interacting with it. On interaction I’d have the UI display and give me options. The interaction part is where I’d get and store a reference.

What class is loading the UI?

The basis for my game is a tutorial posted by Cesium: Build a Flight Tracker with Cesium for Unreal – Cesium . So the aircraft is a static mesh in a blueprint that moves around the Cesium globe along a track that is set in C++. I made it bigger with a widget and some buttons, but it is still blueprint with a static mesh that moves along a track. Does this help?

This works! You said not recommended, so what do you recommend?