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.
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
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
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.
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.
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.
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.