Can't change boolean of a different blueprint

I have two blueprint, Door and Key.
The Door has a boolean variable, set up like this:

I’m trying to change it through the Key blueprint, and then destroy the Key object.
I tried doing it by using an actor reference and casting it to the Door blueprint like this:

But that didn’t work.
I also tried using a variable to directly references the door blueprint like this:

When I tried this, the Key object was destroyed when I pressed the button, but the boolean variable didn’t change, and I got a message error about the “Set HasKey” node that I didn’t get on the first verison.

I really don’t know what I’m doing wrong here, any help would be appreciated ^^

  1. How do you set the Actor variable reference?
  2. How do you set InRange variable to true?

My bad, I fortgot about that.
The actor variable is set like this:

The in range variable changes between true and false like this:

][2]

I tested that part with “Print String” to make sure that InRange changes, and it works.

your first image shows how you create the actor variable but how are you settings its value. basically you have to tell the variable which actor that its storing a reference to. put another way how are you telling the key which particular door in the level you want to affect, there could be may doors but you need to tell it to affect door 1 versus door 2.

Okay, I’m not sure if that’s what you meant, but I tried using “Get all actors from class” to access the specific door that is in the level (number 0) like this:

It works just like I needed, the object is destroyed and the boolean is set to true, but I don’t think this is the best way to do it. If I have nore than one door, how do I reference a specific one? And if I’m using an array, how would I assign an index to the doors?

using the get all of class like your doing is not a good way to go about it as its not performant, reliable, easy to work with. for your case there are many ways to handle a door any key system. from what i see in your screenshots youve got two actors a door and a key and you want a key to work with only one door or at least only with doors you specify. in this case we don’t necessarily need to use a system based on references we could instead use something like tags to differentiate things. Tags are like a note attached to your actor that other actors can check. using this system we could in the door have a script that on overlap with a key checks the keys tag and compares it to a value the door knows (one specific to that door). in this way we would know that the key works for this particular door. you would however have to set a variable on the doors and the tags in the keys by hand so this system wouldnt work well if you spawn the keys at runtime.

below is a example. for the script you can see that on begin overlap we cast to identify the actor as a key. then we use the actor has tag to compare the keys tags to a given doorID which is a public variable. a public variable (denoted by the open eye icon) allows you to set the variables value in the level editor details panel to a different value for each door. back to the script if the key has the tag then the branch is true and we destroy the key (or unlock door). now for the key all you would need to do is to select a key you place in the level and in the details panel in the actor section look for where it says tags. there you just add a doorID value that matches the door you want to open.

this idea could also be done in a few other ways.

one way is that in the key you could use a public variable whos type is actor object reference. since its public then when you set it in the level editor you will be able to select from a list of actors in the level (specific doors for example). then compare they overlapping actors of the key to the variable its looking for.

this is one of the ways of getting a actor reference. others include using traces or collisions as seen with the begin overlap whos other actor pin is a actor reference.

of course this is all assuming that your working with two actors for the door and key. theres also methods which use a array to store which keys have been unlocked like a keyring and is stored in the player. in this case if you think of the old doom games, you would have a array of bools and index 1 would represent the blue key, index 2 the red key, index 3 yellow etc. then when you acquire the key you just set that index to true and when you want to use it you just have the door get the array and check if the appropriate index is true.

The key is only spawned during gameplay, so I can’t use the public actor reference method here, but thanks for the tips, I’ll look into them ^^

The key is only spawned during gameplay, so I don’t think that the tag method will work in this case, but I’’ try looking into tags in general, thanks for the tip ^^

if your spawning the keys then you could also try using a variable in the key instead of a tag. then you could have the variable set to expose on spawn so you can set its value when you spawn the key

Seems your actor reference is not correct, so the cast fails. Essentially, you have to make ‘key’ aware of the existence of ‘door’, specifically the one you’re currently overlapping.

My suggestion based on your current setup: Since you have the ability to get the ‘Player Pawn’ in both BPs, then you can use that to tell ‘key’ all about ‘door’. Make a variable on your pawn called ‘CurrentOverlappedDoor’, and set that each time you overlap a door. Now, when you use ‘key’, once again cast to your pawn, get the correct reference for ‘door’ (CurrentOverlappedDoor), and use that reference to cast to door and set the boolean.