Getting a Variable from another Blueprint
So I have a simple test I wanted to do in order to understand casting and the sharing of variables from blueprint to blueprint. I am using the third person template and I created a blueprint called "BoxTest". Essentially, it is a collision box in my scene that when the character overlaps it the BoxTest blueprint sets a boolean variable called "InBoxCheck"(which is set to public, IE the little eye is open) to true if the character is in it and then sets it to false once he walks out. It also spits out some text to let me know what state the boolean is in.
This works fine. The problem I have is in the next bit of code I want to do. I made a key press event in "Third Person Character" BP that when I press "Q" It casts to "BoxTest" BP, gets the state of "InBoxCheck", and depending on if the boolean is true or false it spits out some text.
My question is what do I put in that object wildcard under the cast in order for it to work. Am I understanding casting right that it allows you to get the information from other blueprints to use in another blueprint. If not please let me know how this works or point me in the direction of some good videos or articles that explain it. Thank you!
asked Dec 12 '18 at 05:00 AM in Blueprint Scripting
Thank you all for the replies! It put me on the right track and after a few hours of tutorials and articles these are two "fixes" that I cam up with. I will explain them the best I can so others might be able to learn.
The first fix is using "Get all Actors of Class" inside the Third Person Character blueprint.
So I guess in this instance I don't even need to cast to my "BoxTest" BP. It did work but the cast gave me a Note at the bottom saying that I didn't need to do it as I already had a reference to it. I simply used "Get all Actors of Class" and from the out actors I used "get(a ref)" under the utilities for Array. Since I only had 1 BoxTest in my scene I knew that the index would be 0. If I were working with multiple "BoxTest" blueprints in my scene I would have to find a way to specify which instance of it I wanted by knowing what index it is at in the Array. But since there is only 1 this works fine. From there I got the boolean "InBoxCheck" but I had to uncheck the "Context Sensitive" box as It wasn't coming up. After that it worked fine.
The second fix I did was doing the keyboard event in the level BP.
This one was super simple. All I did was click on the box in my scene then go into the level blueprint and right click on the event graph. Right at the top there was a selection called "Create a Reference to Box". I clicked it and did the same steps as before just without the "Get all Actors of Class".
Thank you all for the help. Let me know if this looks right or I can do something simpler. I hope me explaining what I did helps someone else out because it seems so hard to share variables in UE4.
answered Dec 12 '18 at 07:23 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here