So I’ve made a map Widget for my game, and have a texture in the widget for setting the map, but I have three different levels with three different textures for the maps, as of now when I go to different levels I have to go in and pre set the map texture to the corresponding map, but I need a way for the map texture to be set automatically to the corresponding level on play. I tried getting the references to the map system, and then a set texture node in the level blueprint, but nothing changes.
Hey @Fettman89, hope your day is going well.
My suggestion would be moving this logic from Level Blueprint to Game Mode or a dedicated actor that would be placed in each level.
You could Get Current Level Name which will return a String with map name then use a switch statement to set texture variable.
After that you can have your Widget access the Game Mode texture variable. You can have exposed variable on your widget that you could set when widget is created and before it’s added to viewport (or as a child). Your widget would handle assigning the texture as brush to the right image component. Should work just fine on Event Construct.
Game Mode is easy to access (ideally via interface) from everywhere as oppose to Level Blueprint.
If you need an example let me know, I will put something together.
Hope that helps!
Hi there, thanks for your response, that does sound like a good suggestion, I would love to see an example if you’re up to it, it sounds straight forward, but I’m still a noob with some stuff.
Assuming all maps are using the same game mode, you could do something like this:
You would need to add a pin in detail panel for Switch on String and give it a matching name (has to match the level).
Wherever you create your map widget (be it player or controller) you would do something like this (showing both direct cast and interface (you would need to create one and assign it to game mode)
Blueprint Interfaces Documentation
and here is a widget.
Make sure your “expose on spawn” and “instance editable” boxes are check in details panel for Texture variable inside the widget. This is what give you an input pin on Create Widget node (once you select the right one from the list). If added create widget node before you exposed the variable inside the actual widget, right click on the Create Widget node and click “Refresh Nodes”. Make sure you compile first too.
Please note this is “bare bones” super basic setup. If you plan on having a lot of maps in your game, your switch statement might get quite big, in that case might have to look for another solution that would scale better.
Hope that points you in the right direction. If you have any questions, do not hesitate to ask, I will do my best to answer them.
Wow, oh thanks this is very detailed Thank you very much, I’ll start trying to implement this and see how it goes, as far as more maps I’m fairly certain it will just be the three, I may add one extra in the future, but no more than that for this particular game. Thank you for making yourself available for extra help if needed, it really means a lot.
On your first picture at the end of the switch on string you have set map texture, how would I go about getting mine into the game mode? My map system is basically a component that handles all the player location, rotation, and landscape to map calculations, then there’s a widget for the map and character icon, that is inside another “Main map widget” that’s called onto the viewport by the character pressing “M”
I followed this tutorial to create my system, if it helps.
If I understand you correctly, you could do all this inside your component. It would be another variable inside this component.
Where does the component exist? On Player Character, Controller, other Actor (Manager).
When you create a widget for the first time (M) you could pass over a reference to said component. That way you will be able to access any variables from it. I’m assuming you’re doing something similar already for other parts of your system.
The switch could be placed on begin play for this component.
Yeah, the component exists in the character.
Something like this perhaps. Exactly the same concept as before with Game Mode but instead of handling the switch statement in Game Mode you do it inside your component, which is created together with your character after the map is loaded.
You can left click your component inside your character and drag it onto the graph, this will act as a reference to it (similar to actual variable).
Again I’m using a bare bones setup here for clarity. I hope you’re not destroying and constantly re-creating map widget, it’s far more efficient to toggle it’s visibility on/off and only create it once (when you open the map widget for the first time or even before that. eg when character is first spawned). This should reduce potential frame spikes when map is being opened.
Ok That seemed to do the trick, I was a little unsure at first on how to implement everything, but after a little trial and error I got it working, you’re awesome, thanks for all your help!
Awesome, well done! Happy to help.