Need help with target actors

I want to refer to the Boolean variables from another blueprint so when I get it, well it does this. I do not know how to make the target the other blueprint which is what I think I need to do anyone have any ideas?


You need a reference to the object that holds the ‘GreenKeycard’ variable. If there would be multiple enemies with a possibility of holding a keycard, how would the game know which enemy it needs to check?
In your case, assuming that you are currently in PlayerController, and that the boolean is on your player character, you could use the ‘GetPlayerCharacter’ or the ‘GetPawn’ nodes. Using the returned reference, you could cast that to your own player class, which would give you a reference that can be connected to the ‘Target’ pin of the keycard boolean node.

Hard to tell what BP you’re in, but yes. You need a reference to the other actor, which means you have to find a way to get that reference and cast to its actor instance.

So if that’s your player, you should set up a member variable called “RefPlayer” that’s a type that matches your player character’s actor object reference, then GetPlayerCharacter > CastTo (that actor) > SetRefPlayer (using result of cast to set the reference)

Then you can use RefPlayer as the input for those nodes.

So I tried get player character cast to the greenkey card which is what I click, the boolean is set to true when the keycard is clicked but when I print the booleans value it says false even though I am using event on clicked, The little robot guy is the 2dsidescrollercharacter and the green keycard is “greenkeycardbp” I know I am doing something wrong as I am very new to this, also thank you for the help.

This is the robot and keycard

You’re using a sequence and casting / printing at the same time. Sequence nodes run the code in parallel, so you’re trying to assess the variable before its reference is actually cast.

Put the branch and print after the cast in the execution flow.

You’re also using “ref player” wrong. You have to have a valid reference to your robot somehow before you cast, so that input end (Object) is where you need to plug in your GetPlayerCharacter node.

Another thing to add:

You should only use sequence if you are plugging in executions that don’t rely on or need to wait for anything in other attached execution flows. If Then 1 needs a result from something out of Then 0, you shouldn’t have a Then 1; all of that code should be on the end of Then 0. And if you only have a single Then node, just delete the sequence node altogether. Each node adds to your start-up memory when you play the game.

So your methodology may be the issue, having looked closer at your blueprint here.

You’re casting to the GreenKeycardBP so the player character cast won’t work because the keycard isn’t a player character. You need to move the logic to the ‘right place’. Instead of having the keycard tell you if it’s been picked up, let the player character tell you if it has a green keycard.

So on your GreenKeycardBP, on begin play, GetPlayerCharacter> CastTo2DSideScrollerCharacter > Set PlayerRef (from* As 2DSideScrollerCharacter *in the prior cast). So you’ll need to create a PlayerRef variable of type 2DSideScrollerCharacter in your GreenKeycardBP.

Then in your 2DSideScrollerCharacterBP, create a boolean for the keycard (bHasGreenKeycard).

Back in your GreenKeycardBP, drop your PlayerRef into the graph, drag out, and Set bHasGreenKeycard, then have your OnClickedEvent0 event execute only that.

In your 2DSideScrollerCharacterBP, delete all of your logic on M and just have it print the value of bHasGreenKeycard.

I did what I thought you meant, Do I have to leave the set Player ref like that, I feel like I messed that bit up, but it is still sending false, when I set a printstring directly to the on clicked it doesn’t do anything so I am wondering If I messed up the onclickedevent_0

Set the Keycard’s PlayerRef variable to the value of what returns from the cast, not the 2DSideScrollerCharacter’s PlayerRef. You don’t need the 2DSideScrolleCharacter to have a PlayerRef at all; that just refers to itself.

You can also keep your Bind Event To OnClicked if you need to.

ok that seems good, but when I click on it nothing seems to happen, I think something is wrong with the onclicked event, even when I use the bind event it doesn’t work,