Announcement

Collapse
No announcement yet.

What is the object in the casting node?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    What is the object in the casting node?

    Could someone explain to me what is exactly is the object in the casting node? I've had many instances where I've tried to set a variable in another blueprint but I have no idea what to connect to the object. Some examples would be nice.

    #2
    You need to get a reference to whatever you want to cast to. For example, if you were to set a variable in your character blueprint, you'd do: Get Player Character -> Cast to MyCharacter -> Set variable
    The "object" is the world reference of the object to be casted.

    Comment


      #3
      Casting is a way of treating a generic object as a more specific class, typically.

      So for example, say you wanted to do something specific with an enemy's Blueprint when he overlaps the player's sword. From the EventBeginOverlap event, you can get a reference to the Actor which was overlapped, but you need to call a specific "Take Melee Damage" function in the Enemy class. You take the Actor reference and you CastTo your Enemy class; the Actor reference is the Object, and it is then "converted" from a generic Actor to the more specific Enemy (and it will execute Cast Failed if the overlapped Actor is NOT in fact of the Enemy class), which allows you to then take the new Casted reference and call the Take Melee Damage function.

      Two other VERY common casts for me: communicating between an actor and its animation BP. Try Get Pawn Owner on an anim BP returns a generic Pawn reference, but because you know (usually) that this Anim graph corresponds to a specific class of Character or Pawn, you can Cast the Pawn reference to the Character Class. Vice versa also applies; from a Character BP I frequently use the Get Mesh > Get Anim Instance chain to get a reference to the generic anim instance, and then Cast this to the Anim BP I know that Character will use.

      This lets me do things like use specific input commands on a character to trigger transitions or Montages on my Anim BP, and also lets me use Anim Notifies to send Character-specific events such as disabling certain inputs or changing collision responses temporarily.
      Last edited by RhythmScript; 08-15-2015, 08:31 AM.

      Comment


        #4
        Thank you, your explanations help a lot.

        Comment

        Working...
        X