I’ve read the documentation on blueprint communication and none of it makes sense to me. All I want is to have a bunch of variables that can be accessed by multiple blueprints, and I also want to save them. The saving part seems pretty straight forward, but when I click a button on a widget I want it to modify a variable in a different blueprint, and I have no clue how to do that.
My blueprints are created in the game and not directly in the level editor, so I think that’s part of the issue. I’ve googled this problem and watched videos and I still don’t know. Isn’t this an important part of programming? Having two different things talking to each other? Why does it seem so difficult in unreal.
This was confusing to me as well when I first started working with Unreal. I won’t pretend I understand it from an engineering standpoint, but you need to use one of many ways to get a reference to the BP you want to modify. Depending on what you want to do, different methods might be better than others.
If you have more information on what exactly you’re trying to do, I might be able to help you. But, here’s a couple stabs in the dark that might help.
If the BP class (target) that you want to modify with your widget is spawned in the game, then you should be able to use a node in the widget BP called ‘Get All actors of Class’. Then in that drop-down, search for the name of your class. This node will return all actors currently spawned in that class into an array of that type. If you know there’s only one in existence at a time while playing, then you can drag off the array return and find the node “Get”, which will get from the array and the default will be index 0, that will be your target BP class. On the “Get” node, the return pin will be a direct reference to your target BP class and you’ll be able to access all it’s settings, variables and functions when you drag off of it, just like you get when you’re in that BP directly and right click (provided, of course, that you’ve successfully found one in the array).
(To check if it found one, you can drag off the Get’s return and add a node ‘Is Valid’. There are two types, one is a pure function that will return a true/false, the other is an execution pin that will act like a branch in this case; pick the second one. If it found one, then it will be valid, so you can continue from there. the editor will let you continue regardless, this is a check for Play/runtime to ensure you don’t get errors, or maybe you want to do something else if that BP doesn’t exist when you click the button, like print an error to screen for debugging.)
Hello, I recommend you try and understand the basic design principles regarding blueprint comms. It is also not clear to me what you want to accomplish in concrete terms (use a widget actor placed in the world and click on buttons by which save data in other classes?) so I will just give you general advice. Of course, you can use Get all actors of class but if you find yourself making heavy use of it it just means you do not understand the communication framework and there is a flaw somewhere.
UE4 was not designed in a way that you can just shout out into the world and say “hey actor I want to communicate with you, I wanted to change your variables”. They tried this in UE3 and it was not good. There are essentially three ways:
So the best way is to obtain a reference of an actor instance, cast this instance to a specific actor class and then you can access its member variables and functions. This is called direct BP communication. You use this if you have a clear idea in advance to which class you want to talk to from where.
If you do not know in advance who you want to talk to or you do not specifically care, you use interfaces. You just implement the interfaces in those blueprints where you want to receive interface messages (which transmit data) but you can implment own funcationality in each class.
Event dispatchers. Now I will not go in there because approach 1 and 2 will be enough 98% of the cases.
From what I understand from your short description: You want to have some class containing a widget with buttons which should somehow control the world or at least some actors in it which are not really related to the widget actor anyway. This is not ideal as it does not follow the idea of an object-oriented language but it is possible to do it.
You place the Wdiget actor blueprint in the world.
You expose variables in that blueprint (make them public) with the type of an instance of those classes you are interested in.
Go to your scene find the widget actor and you will see the “picker tool” You can then pick actors (or your derived subclasses) from the scene and save them. You will then be able to access them in your blueprint.
And then from your widget blueprint you just get the owner or parent, cast it to the Widget actor blueprint and there you have, you will be able to access all the desired actor instances.
It seemed to me like I should have multiple widgets doing multiple things. Just to test things and learn BP communication I made two widgets which are spawned by a custom camera controller
Widget A will increase an integer variable by 1 when it’s button is pressed
Widget B is the menu, saves, loads, quits the game.
I want to be able to save the integer value of the variable in Widget A, but Widget B is the thing doing the saving. So somehow I either need to send the value to Widget B or get the save instance from Widget B to Widget A. Does that make sense?
I did look at interfaces but my understanding of it was that it was just functions, which didn’t make sense to me. I even watched a video on it, but perhaps there’s something else I need to watch.
I can try the get all actors of class thing but yeah my understanding of that is that it’s really inefficient.
I don’t want to make a game that has characters running around, I want to make a management/strategy game. So that makes things a little more difficult, I think.