Returning a Boolean from a Blueprint is unpredictable

I have a simple testing script that is supposed to return true if the branch statement is executed and false otherwise. In my testing , I am finding that it always returns false, and I can’t figure out why. I am new to Blueprints so I may just be overlooking something, I am also using version 4.6.1 so this may not be a problem in 4.7.

This is my Return Boolean method in my Test class.

This is my MyCharacter class where the Return Boolean method is called. TestVar is of type of my Test class.

That’s pretty weird. Have you tried putting a .1 delay in front of the Print String?

I just tested that in the editor and it still is returning false.

Go into debug mode and watch that function. Is it actually firing off?

I say this because you will likely need to cast to it to actually get the instance you’re using

Hey,

when you create an object variable you need to select which particular instance you want to assign to it. By creating the TestVar and just making it a Test class variable you still haven’t filled it up. It’s just an empty variable. Therefore the target would be non existent and the function won’t be executed.

Also, have you enabled input on that blueprint? To use the input events you need to enable input on that particular blueprint, so that the blueprint will listen to the player controller’s inputs.

Hope that helps~

EDIT: nvm about the second part… just noticed that your event is inside the character :stuck_out_tongue:

Could you explain how to implement the first part of your answer? I am a bit new to blueprints.

How do you go into debug mode with Blueprints?

Hit play, make sure your bp is open in front of you, and click the debug object dropdown in the top left

Well, there is 2 options. A simple and a slightly more complex one. If both blueprints that you’re using are in the scene then you should just be able to set it as a default value for the variable, however if one or both blueprints are not in the scene then it’s slightly more complex.

I assume your character blueprint is not part of the scene, but is your test blueprint in the scene?

I will work on getting up a quick example for both cases while I am waiting for a reply :slight_smile:

Apologies, there is indeed 3 different options.

If your CharacterBP and your TestBP are both in the scene:

This is probably the easiest. Start by going into your player blueprint and setting the TestVar variable to Editable by clicking the checkbox.

31396-testvar.png

Then make sure the TestBP is within the scene and select the CharacterBP in the scene. In the details window you will find that you can set the default value for TestVar. Select the TestBP that is in your scene and you’re done. The TestVar will now hold that particular instance.

If only your Test BP is in the scene:

This seems to be the most common with older versions of unreal (4.6.1 and lower.) You will need to use what’s known as ‘casting’ in order to assign the value of the TestVar variable. To do that go into the level blueprint.

Within the level blueprint, you need to cast to your existing TestBP. To do that just create a “Cast To TestBP” node (I named my blueprint TestBP, so yours might be different!) Select the TestBP that is within your scene and right click anywhere in the graph to ‘create a reference to TestBP’. Connect that reference into the object input of the Cast To TestBP node. Then cast to the player blueprint and this time plug a “Get Player Character” node into the object input. Then ‘As PlayerCharacter’ you set TestVar and connect the output of the Cast To TestBP into the value for TestVar.

If your TestBP is not in the scene:

In this case you’ll have to create an instance of the TestBP first. To do this you can use the “Spawn Actor from Class” node. You can do this anywhere, at any time, but keep in mind that you will have to cast to the CharacterBP to set the TestVar value if you don’t do it straight inside the CharacterBP. (In my case I did it straight inside the CharacterBP, using the Begin Play Event).

For the Class field of the SpawnActor node select your TestBP and for the Spawn Transform of the SpawnActor node, you’ll have to put in the transform at which you would like to spawn the instance. (A transform is location, rotation and scale put together into 1.) In my case I just chose to spawn the TestBP at the character location, so I just used the Get Actor Location node.

Finally just select the output of the SpawnActor to set the TestVar variable.

Also check out this: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintCommsUsage/BPComHowTo/index.html

And this:
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html

Thanks for the information on getting into debug mode. When I run it, it looks like the method is firing off without a problem.

So you ran debug within the test bp, saw it go through the branch, and through the Return Node?

Thank you for this incredibly clear and detailed answer. It solved my problem and will help others who stumble upon this post.