Getting a variable from one blueprint in another

So I need to call a function that gets a byte variable from my player blueprint and allows it to be used in a separate blueprint. I don’t know how to get this to work…can someone answer this question?

Hey Millan,

Thanks for the question! Here is a quick example, using the First Person Template, of how you would pass a Byte variable from your Player Character to another blueprint using an Interface:

  1. Create a new Blueprint Interface, add a new function with a Byte Output, Compile, and Save.

  1. Open the MyCharacter blueprint (again, this is created by the First Person Template, so you may use your own Character blueprint here) and select Blueprint Properties. Here you will want to scroll to Interfaces > Implemented Interfaces and Add the Interface you just created. Compile the Blueprint.

implementinterface.jpg

  1. After compiling, you will see the function from your Interface added to the MyBlueprint tab of your Character blueprint. Double-click on that function to edit it. If you don’t already have a Byte variable created, you may add one now. Set the default value of your Byte to a test value you wish to pass to another blueprint. Drag in your Byte variable to the graph for the function and hook it up to the Output byte pin. Compile and save your Character blueprint.

characterfunction.jpg

  1. Locate and open the blueprint you want to use to Call the function on your Character blueprint–this example will use an Actor blueprint with a StaticMeshComponent. In the Eventgraph, setup the Event you want to Call the function with–I will use Event ReceiveHit in this example. After adding the Event, right-click and search for the Interface function by name–select it from the list to add the function node to the graph.

functionsearch.jpg

  1. From here, you will need to point your Interface function to the Player Character, which you can do by adding a Get Player Character and connecting it to the Target pin of your Interface function. From here you can use the Return Value of your function in whatever manner you wish, I just hook it up to a Print String so I get visual feedback to know it is successfully firing off.

And here is the final result, shooting my placed blueprint in the level will return the Byte value from my Player Character and print the value to the screen:

If you have any questions about this setup, please let us know!

Thanks!

-Steve

Thank you! This answers my question exactly! I didn’t know what Interface function outputs were for and now I do!

Right now you will have to use Interfaces. Although Epic confirmed Blueprint Communication which makes it a lot easier. However am not sure when this will be available.

I know that, but I need to know how I would use the interfaces. I have an interface and have used it to transfer changed states and such (I am building this on top of the Blueprint Examples Sample Project), and I know how blueprints work. I am simply having trouble getting a variable from my player to be used in my door class.

“add a new function with a Byte Output” How do you do that? I added a new function but I don’t know what a “Byte Output” is and can’t find it in search like that. I would like to Get a float from a blueprint so I can use the variable in my HUD.

Is there a reason why the printing of the ‘byte’ doesn’t work if I move the interface implementation from MyCharacter to some other arbitrary blueprint, like SaveData?
i.e. Is it possible for non-scene objects to get/set each others variables?

Hello,

This is a question from the beta version of the engine. We are marking this answered for tracking purposes. If you are experiencing an issue similar to this please post a new question.

Thank you.