Set MyCharacter Variable in Level Blueprint?
I have an int variable set up in my MyCharacter blueprint, for a limited resource I want the player to have access to. I want the amount of the int to be different for different stages, so I'm trying to set it in the level blueprint. So I set up a variable for my character blueprint in the level blueprint using the method shown in the Direct Blueprint Communication documentation. But when played nothing happens, and I receive an error message (shown below). Any help on how to resolve this would be greatly appreciated.
asked Sep 02 '14 at 02:44 AM in Blueprint Scripting
You need in your level blueprint:
Begin Play >> Get All Actors of Class (MyCharacter) >>Get >>Cast To MyCharacter >> Promote to Variable (sets a newvar of type MyCharacter, then name it MyCharacterVar).
And get and hook up MyCharacterVar as the target for your set Jumps.
answered Sep 02 '14 at 03:55 AM
You should probably be using an interface for this as directly accessing blueprints like that you need to cast them and its not great practice.
Create a new blueprint interface called 'MyCharInterface' or some such.
Add a function to it, lets says 'SetJumps' and have an input of 'int' jumps and a bool return.
Then on your character blueprint properties add the interface of 'MyCharInterface' and you should see a function prototype SetJumps appear. Now open that up and setup the function to take the input and assign it to the blueprints jump variable.
You can now access this from anywhere by doing:
Get All Actors of Class 'MyChar' -> 'SetJumps'
answered Sep 02 '14 at 09:28 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here