Variables communication.

Hi everyone.

I have been watching videos, reading tutorials and old fashion trial and error for +3 hours now and still can’t seem to figure out what should be a relatively simple problem.
I have trouble figuring out how variable communication between blueprints work.
There doesn’t seem to be one best use of practice on how works, and therefore it seems that all tutorials go about it in different ways.
The problem is more complex than below, but i have simplified it for the understanding.

I have two instances of a blueprint with a simple switch (SW 1 and 2)
I have two instances of a door blueprint (DR 1 and 2)
I have a variable designating the level of the key Var1
Var1 is also used for other things, so i want it to be easy accessed with as few steps as possible.

SW 1 opens DR 1 when Var1 > 1
SW 2 opens DR 2 when Var1 > 2

What is the best way to handle variable (And variables in general)
Do i store them in the player BP, the level BP or do i create a new BP designated for all variables (Like a variable inventory bag)?

Can blueprints trade variable information directly, or do they have to come across the level BP?

I imagine the Var1 as an integer, and then having an array of booleans for each number of instanced doors. How do i make it so that DR 1 is relying on bool1, DR 2 on bool 2 and so on. (As in differentiating instances BP from one another)

I hope you can help, as is a HUGE frustration, and with so much relying on variables it really hinders me a lot.
If it’s not asking to much, can you please also illustrate with a simple setup also, on exactly how you would approach problem.

All help is greatly appreciated :slight_smile:

Cheers

Yea casting to other actors to change and get public variables is a really easy, and simple soulution. Another thing I usually do is create custom events and call them in other blueprints via casting to them.

Although above statements say “You just do and that” and "thats easy and simple :slight_smile: :slight_smile: " time has flown by, and is my closest result (i think) so far.

However i get an error based on the construct script, where i assign an integer individually to each door.

Lås = Lock, Gitter = Door.

Please supply a blueprint if you have the 5 mins it takes for you to make it, or if i do any blatant errors, please point them out :slight_smile:

In your construction script blueprint you are setting the “DorNr.” variable to itself, which is not necessary. You should be setting a value to the “DorNR.” variable instead.

If you modify value from the details panel in editor, then you can just remove the Set node and the variable, since it will be set automatically. So you either want to set it to the value of some other variable, or just remove those 2 nodes from the contruction script and the error should go away.

Hope that helps, let me know if you need more info. :slight_smile:

Thank you for the reply :slight_smile:

I deleted the two, and didnt add anytthing. However now i get an error saying: “Error Accessed None ‘Fra LåsBP’ from node ‘Construction Script’ in blueprint ‘GItterN’”

But the construction script is empty?

Hi Britain

I will try and work from your link when i get home, it certainly looks like it’s going to get it going in the right direction.

Yes, it consists of 2 switches, and 2 doors, and the key is just a variable that change when certain events occur, nothing more than that :slight_smile:

Hello,
@TheBritain : By setting a ref on event begin play you’ll not have to loop

@Fjordhoj : The error with “dor” in construction script is that your variable “fra las”… is not set. You have to set a variable to be able to use it.

Thank you for the replies, and thank you for the Blueprint example Britain.
Can’t wait to try the method out, to see if it’s the magic solution, but it sure looks promising. :slight_smile:
Calling it ID instead is of course the obvious solution, should have thought of that myself :stuck_out_tongue:

Got home late. So don’t have time to work on it evening, but will most certainly try your ideas when i have the time.
Hopefully i do tomorrow.

The Britain, you are my new hero :smiley:

It worked like a charm. Thank you very much for your help and explanations, is going to help a lot.

I finally seem to understand how it works. seem to be a system where the activated BP pushes the variables to the next BP edits it through that. 10 mins of fiddling around i was also able to make the opposite system, where the activated BP correctly pulls the variable from another BP and acts on the information it gets. As far as i can tell, these are the only two ways required to handle general variables in every way needed.

Thank you again :slight_smile:

Problem solved