Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

alt text

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!

Product Version: Not Selected
castproblem.png (103.5 kB)
more ▼

asked Jul 19 '14 at 05:16 PM in Blueprint Scripting

avatar image

6 2 5 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi dougbott,

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.

alt text

Thanks, TJ

more ▼

answered Jul 19 '14 at 06:31 PM

avatar image

41.1k 1009 183 493

avatar image dougbott Jul 19 '14 at 06:33 PM

Yes, You are correct as well. The Tick was just for testing purposes. Thanks!

avatar image dougbott Jul 20 '14 at 02:38 AM

One other question if you don't mind me asking. If I wasn't casting from the player pawn and instead was trying to grab a variable from a random blueprint that wasn't part of the scene. How would I go about that? Thanks.

avatar image ClaverFlav Jul 20 '14 at 07:47 AM

yo dougbott, for getting any other blueprint in the level i often use the "GetAllActorsofClass" (i think thats the name) it will return an array of all those particular actors, which is really only handy if you have only one of them or if you know its name or something else to cross check.


i make actors 'register' themselves to some custom variable in my gamemode class. the only reason i do this is that every class extended from actor has the function GetGameMode which then you typecast to your used gamemode class and access said custom variable via that. :)

also just save that 'MyCharacter' as a variable for later access so you dont have that process intensive typecasting every tick.

avatar image TheDiceParadox Oct 15 '14 at 04:15 PM

Would you mind showing an example of that alternate method? I can't for the life of me figure out casting from actor blueprint to actor blueprint.

avatar image Adam Davis STAFF Oct 15 '14 at 05:14 PM

Hi TheDiceParadox,

The above images should work for a majority of casting. Can you show me a screenshot of what you have? I might be able to see what is occurring.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jul 19 '14 at 06:06 PM

avatar image

3.4k 154 51 271

avatar image dougbott Jul 19 '14 at 06:26 PM

You were correct. It seemed that I was trying to reference the player pawn but didn't know how to get the Get Player Pawn Node. I replaced the Reference node with that, and bingo. Perfect. Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question