How to change another BP variable?

So i made two blueprints, when I press 1 on keyboard I see print string 0, when I press 2 on keyboard I want to set that number 0 to 2 from another blueprint but next time i press 1 on keyboard print string is still 0. How I have to do this?

The communication methods will always depend on the circumstances. There are probably 10+ ways of making those 2 blueprints talk to one another.

Are they spawned with a node or did you place them in the level blueprint?

There’s no good answer to your question atm. It’s a bit like: I have a car, a driver and need to go to X shop. For all we know the driver is in Brazil, the shop is on the Moon, and the car has yet to be built.

Thank you man you are always very helpful.

So both of the blueprints have input actuve from Player 0, they are based on actor and both are existing in the world. Compiled and saved and then I proceed to play. Nothing else except the full starting content in third person shooter

Is it going to happen if I make custom event when I press 2 from one BP, and this event in the first blue print to change its own variable ? Which method is going to be easiest?

So they’re both in the world when we start the game. Got it.

In BP2, you’ve created a TheOtherBP variable and flagged it as Instance Editable. It’s a reference to an instance of BP1. Currently that reference is not pointing at anything - we only know the type of object we will refer to. There might be many instances of BP1! We need to tell the editor which instance we mean.

Providing both actors are sitting in the level:

And there is no need to cast in this very instance.

I see I forgot about that, there could be many instances. I will rework thank you

Is it going to happen if I make custom event when I press 2 from one BP, and this event in the first blue print to change its own variable ? Which method is going to be easiest?

Once you have a reference, it’s up to you. The BP2 has full access to BP1 and its exposed variables.

From a programming point of view, it’s better and safer to write getters and setters - methods / functions / custom events in the target blueprint and call those rather than access variables directly.

Technically speaking, the Exposed for Change shouldn’t really be exposed. Ideally, there should be a custom event / function in the target blueprint. You call the target blueprint’s function and it sets the variable.

But nobody ain’t got time for that. :wink:

You will see this neglected often. I am so guilty of that negligence, too. We all are.

1 Like