Set MyCharacter Variable in Level Blueprint?

Hi all:

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.

14344-levelblueprint.png

14345-errormessage.png

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.

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’

How do I add the MyCharInterface blueprint as an interface? It is not giving me that as an option under MyCharacter’s blueprint properties.

14550-addinterface.png

Is the Get node I should be using after Get All Actors of Class the one listed under Utilities-Arrays? Because that is the only one named simply ‘Get’ I can find (none appear in the context-sensitive list I get from dragging the pin out from Get All Actors of Class). When I do use this Get node, I’m unable to find Cast to MyCharacter from its context-sensitive list to link to next.

Useful info. Could you elaborate on why casting to a blueprint is not good practice? I’d really like to learn more about that.