Blueprint Variable Casting Problem
So I am trying to test out how to cast a variable from one blueprint to another with using casting. What I trying to do i pull a variable value from my character class, and use it in my playercontroller class. A side note is that obviously the playercontroller class is not added to the scene prior to game start, and so I can't reference it through the default value menu. Therefore, I am trying the casting method of doing it. Below is the way I tried to cast for testing purposes. Everytime I get a cast failed. So I am wondering what I am doing wrong. I am obviously missing something simple since this should be a breeze.
Please help. Thanks for any questions or answers given in advance.
Just a quick explination on how I did this network. I first created the refence variable by making a new actor variable and naming it reference. Then I dragged the cast to MyCharacter pin from that and then pulled another pin to find the "Sine Bullet Rate" variable found in the MyCharacter class. Then I wanted to print the values to see if the cast worked properly. Everytime I run the scene I get a cast failed message. Please help. Thanks!
asked Jul 19 '14 at 05:16 PM in Blueprint Scripting
I believe you are off by one node. The reference variable you are trying to cast to MyCharacter should be a Get ContolledPawn node. The reason for this is to be able to successfully cast to your character you need to get an blueprint/object that is interacting with or (looking at) your character.
I would also suggest changing the Event Tick node out for something less memory intensive. I'm not sure exactly how you plan to apply this setup, just make certain you really need an Event Tick before using it. If you are trying to do something every so often I would suggest using a Timeline.
answered Jul 19 '14 at 06:31 PM
TJ V ♦♦ STAFF
Your Reference is always 'None' or 'Undefined'. SO it wont cast to any object which is why its failing. The variable being casted must point to an existing object for it to work.
You can use the Is Valid node to see if your Object reference is valid or not.
It seems to me that you are trying to reference your Player Character. The best option here would be to use Get Player Pawn from Controller and then cast it to MyCharacter. Another option would be to select all instances of MyCharacter from the scene using Get Objects of Class node. Then iterate through the result using a for-each.
Follow this question
Once you sign in you will be able to subscribe for any updates here