Creating a system to change specified materials
I'm trying to use UE4 to do some arch-vis work. I need the ability to change between different styles in the level through a menu, which will change materials on some of the actors in the level.
I've got some ideas but I'm new to UE so I am not sure if there is an easier or better way to do this.
At the moment I've got my style changer widget which shows the menu and handles the logic of changing the styles. I was going to implement a global event system and have the widget broadcast the style that has been selected, and then have a blueprint component assigned to the actors that I want to change materials for. This blueprint will listen for the event and switch the materials.
Two questions - firstly, does this sound like a good way to handle this?
Secondly, none of this data needs to be set at runtime or dynamically; the styles and the materials to switch between are all pre-defined. What is the best way to handle this in the editor? I have created a custom struct which is used by my style changer widget which is an array that contains the name and a few other pieces of information of each style. I then wanted to have each blueprint component on the actors read that array and, in the editor, pre-populate it's own array with the styles from the widget so that I can then assign materials. I can access the widget's styles variable at runtime, however, I can't find out how to run a blueprint in the editor such that the array will get pre-populated with the styles. Is this possible?
I'm currently using blueprints for this, but I can use C++ if it will work better.
First, yes, I think that's a great use for global events - since you don't have a pre-populated list of actors to call.
I don't quite understand your second question, but the way I would do it is take a global object like the gamemode, add in a variable of your struct, click the array grid. Then, in the default for that array, add in the data. If you only have the name (and can't create a reference directly to the material), then you have to do more fixup, but the gamemode or gameinstance is probably a reasonable place to do that as well. If you send a picture I can probably give you more targetted data.
The actors can GetGameMode() -> Cast to your game mode() -> access the array.
answered Feb 23 '17 at 05:52 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here