How to set/get variables from another blueprint?

The question is straightforward. I need to get value of public variable of the 1st BP in the 2nd BP and then change it. In the 2nd BP var looks like this →

50830-blueprintspublicvar.png

There are a couple of ways to go about this. My preferred way is to create an Interface BP, and give at a Get Value/Set Value function. Implement that interface on your object 1. In object two, get a reference to object 1, and call the function via the interface. That works great if it is something that you will be using for a lot of different objects of similar types. I.e. Enemies, lights/switches, etc.

Option two is to get a reference to Object1 in your Object2 BP, and use a cast to node to get/set the variable directly.

The hardest part is getting a reference to the correct object. That can be done in a number of ways, such as collision detection, getting a reference from your level/game instance BP, Get All Objects of Class, Get all Objects with Tag, or setting it via an On Touched/On click function. Without knowing exactly what you are trying to do, and what the scenario is, it is hard to say which method would work best for your situation.

Input the reference of object from blueprint that variable you want to access in to “Target” input. “Target” input is always for object you want to operate on, in nothing is plugged to it, it defaults to “self”. To get that node from object you need to hold the link from that object and drop it in empty part of blueprint so it shows all possible connections, in “Variable” category you will see get and set nodes of all public variables of object.

You don’t need interface you can just cast, interface is for relate unrelated classes not for communication which lot of people misunderstand,

Here you got my video which explains class relations and inference and also little about interactions of blueprints

Maybe I have more complicated situation. I have 1st object which is spawned with “SpawnActor” func and from there I spawn another object which I want to somehow reference to another new BP. Also I want to get/set variable to this new BP from 1st object. Sum up, I don’t have objects in the scene, I’m spawning them in blueprints and the problem is - how can I pass objects and variables, which exist only after spawning of actor, between BPs?

Please, check my comment below. I think I have specific situation so I really don’t know how to use your advice.

Create Two variables in your level blueprint. When you spawn the actors, set those variables as a reference to the actors you just spawned. Then, you can reference those variables anywhere in your script with a Cast To node.

You could always store the values in an array inside the “Game Instance” blueprint, and just cast to the game instance array to make any updates on your objects, using the index as a unique identifier for the objects in question.
When you spawn a new object, you assign that the unique identifier, by getting the length of the array+1 for its ID and then writing a blank value to hold its place.

Game instance would be good if you want them to persist across levels. If they are only being accessed within a single level, this would be a waste. Assigning unique identifiers is only a good strategy if you know in advance which objects you will need to access. Otherwise, it is better to match names to names or object to object if you have references.

… check this one , I used GameMode object as “Cloud” object for referring data in live time … ; ] ,