Trouble casting to blueprint

Ive created a blueprint to hold my weapons data, and Im trying to cast to it to fire off an event, but the casting fails no matter what. I know it has something to do with the object reference. What do I connect to get the player to effectively cast to the weapon blueprint?

You can add a Variable to your character of type Actor called, for example, “MyWeapon” (assuming you may want several weapon types later on). Compile and then set the default value to your AK74. Drag MyWeapon from the variable list and connect to the Object pin in your Cast node and it should work. As shown, you’re casting basically nothing to the type AK74 which is why your cast is failing.

Thanks for the reply, Ive tried adding the variable, but I cannot give it a default value.

http://i.imgur.com/qQrusgw.png

So I changed the variable to object instead of actor so I can set a default value, but still the casting fails.

http://i.imgur.com/UpH9Jg1.png

Ok - long shot, but this happens to me sometimes too. Try deleting the Cast To node, pull a line off your Weapon variable there and add a new Cast To AK74 node back in. Seems dumb but sometimes if you create the cast out in thin air instead of pulling off the variable first it gets a lil confused.

Thanks, but it still doesn’t cast properly, still only failing,

Maybe you have a null reference. Try to spawn the AK74 (“Spawn Actor from class”), and then set your variable to this spawned AK74. Next, try to execute “Fire” from this variable (or firstly cast it to AK74 if it fails)
If you want to use your class (blueprint) it must be spawned somewhere first.

Use Interfaces. They are MUCH more reliable and easier to work with. I know that is not what you are asking, specifically, but sometimes the best answer is simply to do it a different way.

Also, I can’t tell, but is your weapons blueprint actually an object somewhere? If not, that could be why. I don’t think you can cast to a class. If there is no object instantiated then there is nothing there for you to cast TOO.

What he’s saying is that the blueprint is like written instructions on how to make a gun. You’re trying to tell the instructions to fire bullets, which doesn’t make sense. Especially here because the blueprints don’t actually exist in the game - only actors spawned from them do.

So first, you need to use the instructions to make the actual gun in the game world, then in here try to fire that gun and not the instructions themselves. So somewhere else in your blueprints (maybe Event Begin Play on the player), spawn a weapon from class AK74 and save that as your weapon variable.

Im trying to use interfaces for all the shared weapon functionality like fire, reload, draw, idle, ect. And Im not quite sure what you mean if my weapons blueprint is an object somewhere. I have my weapon blueprint that contains the weapons mesh and the included weapon interface.

Exactly so.