What do I cast in the cast function?

My problem seems to be quite a simple one,
as my casts ALWAYS fail and I think its because I just dont really know what I am supposed to cast.

I am usually making a reference to self.

Example:

I want my weapon to start firing when the Action “InputActionFire” is called by the hero, and therefore I made a tick and then casted to the hero class ( self). After that I “got” the variable I set aside for that and checked it with a branch… the cast fails tho :frowning:

Thanks in advance

So your pawn is casting to your pawn or did I miss understand you?

Howdy

WHen you cast, you cast to ANOTHER BP, not your own, as the Variable is already there.

Here is a quick example.

38556-capture.jpg

BP1 - I made a Variable

38557-capture.jpg

If I Want it, just drag it out.

38558-capture.jpg

In BP2, if I need it I cast.

2 Likes

Well I’m not sure what your problem is but here are few examples of casting:

works thanks so much yea I am still a started and realised that making EVERYTHING in the Hero class is not very smart ^^ you’re my saviour

If I could find one ■■■■■■■ decent explanation of casting I would have figured this out about a month ago. For one thing whatever your saying doesn’t work. The array goes somewhere, then you have a node out of that into “”. Well how do I even get that. How do I get from out actors to ? I’m becoming more and more convinced they make this hard on purpose so no one will compete with unreal tournament.

when I do that it comes up with this (The current value of the ’ Array ’ pin is invalid: Array inputs (like ‘Target Array’) must have an input wired into them (try connecting a MakeArray node).)please help

when I do that it comes up with this:
(The current value of the ’ Array ’ pin is invalid: Array inputs (like ‘Target Array’) must have an input wired into them (try connecting a MakeArray node).)

post a screen shot of what you are talking about

I think that this is the hardest concept to grasp, yet seems the most common sense, with oriented programming.

A lot of the struggles I have when I am trying to code on my own go back to casting. I know I need to cast to get a reference to another BP, I know that I can make a reference variable to call from once I have casted… But… Before you can truly cast… You need that ‘’ input taken care of.

Easy enough when it’s just ‘GetPlayerController’ or ‘GetPlayerCharacter’… But when you try to reference one of your custom objects… That’s where my brain shuts down.

, this helps me so much with so many situations. Thank you! Great post!

For more in depth look at this subject check out the first video about casting and the 2nd last one about creating references I think it will help clear some stuff up if you are having any other troubles

Unreal Engine 4 Beginner Tutorials: https://www.youtube.com/playlist?list=PLyu-W38DvZhqByAoeva1jewB5s78zQHIy

You took my “nobody explains this well” as me saying nobody put the effort into explaining this well but thats not the case. Truth is it’s a difficult concept to explain well as is evidenced by how many posts there are with the same question saying they all did the research but still cant understand it. But yeah be frustrated with us, makes us feel all warm and fuzzy opening up to the community for help!

nobody explains this well […] So frustrating.

The only more frustrating scenario is folks refusing to go through elementary tutorials and docs:

If you want to directly refence something from the level in the player blueprint:

  • create a reference variable of the appropriate type in the player
  • flag the variable as Instance Editable
  • point it to the desired instance

Try these videos I made going over the whole concept of casting. First video I believe in the Playlist and the one about reference is also useful for understanding the concept.

Just wanted to say your solution was exactly what I was looking for. Thanks!