I have a question. I get an error when I use the widget variable I created in the character blueprint in the BP_Weather Manager blueprint. Thanks for any help.
You are missing references to some object\actor.
I am guessing now (because your code looks correct).
Order of created objects in memory is not guaranteed.
So you cannot be sure that BP_weather manager is created before hud, or map.
So if its created after, map reads empty variable, sets it to null and then you have errors.
To debug this add some function that prints warning that variable is nil and prints name of actor (self reference).
Some better way to structuring and solving all UMG problems:
After some UMG cthulu coding i decided to make my own message system, it saves tons of time and code. Also classic\simple way of communicating becomes really hell when you start dynamically creating widgets. Referencing parents childs etc gets messy fast.
First, umg\hud is there to only display info, it should never process anything (besides some scaling numbers, formatting text etc.). So if its only one way information to process (only gets info and every widgets only displays it never returns anything). For that DISPATCHERS are best, well they are made for it.
So to create single dispatcher that can solve all hud problems it must:
- be created either in player controller, pawn, or in game mode (easily accessible by everything).
- should be able to transmit any message to whoever wants to listen.
How i made my message system:
- create enumerator that has names of info they are transmitting, like player HP, gun ammo, rockets, temperature etc.
- create dispatcher that has above enumerator and string variables.
- hud may be updated 4 times per second and nobody will notice, so make timer or count seconds in event tick, and fire only so often.
- fire dispatcher, convert variable you want to send into string and set enumerator
- in widgets assign read value function to dispatcher, check if enum is correct, then display info
If it is singleplayer game i use game mode, because it is easiest to acess from level blueprint and everything else.
Hello, thanks for your help. I’m not advanced at this. I don’t know what to do about Dispatcher. Can you send pictures?
There was great resource about dispatchers, sadly pics are missing now:
However you have choice: dig yourself in blueprint communication and dispatchers and learn by trial and error, or ask uncle google about those and follow some tutorials. You need those soon or later, so why torment self.
If you reference a widget in one blueprint, the other blueprint does not know about it, that’s normal. You’re not really “use[ing] the widget variable I created in the character blueprint”.
If you create a variable in the BP_Weather Manager, it’s null, it’s not associated with anything. Creating a variable does nothing on its own, it also needs value.
Perhaps the simple solution here is to created and reference the widget in the BP_Weather Manager - it seems you need it there.