I always face this problem that prevents me from continuing my work. When casting to I don’t know what to put on the object as I have no idea what object means. So I don’t know what to put here and I don’t what to put in any object pin when I cast. Please someone explain what exactly is object pin?
Do you have a reference to the bullet in the character? If so, you don’t need to cast…
Whenever you use a Cast, you are asking if the provided object extends from the specified class you are casting to. In the example below, I am casting ‘self’ to do different classes; FPPCharacter and TriggerBox (keep in mind this is done in my character Blueprint that extends from class FPPCharacter, so ‘self’ is referring to my character Blueprint).
Although both Casts will compile, the cast to TriggerBox will fail because self (my character Blueprint) does not extend from the class TriggerBox; however, the cast to FPPCharacter will be successful for the same reason I just provided.
To answer your question in one sentence; you need to tell the Cast which actor/object you want to attempt to cast with. Here is a link to some UE4 documentation that outlines what Casting is: Casting in Blueprints | Unreal Engine Documentation.
Correct me if I’m wrong. From what I understood, it means that when we cast to a class, we decide what do we need from that class or get from that class, is it our character or other things.
When we cast an object to a class, using the Cast node, it returns that object as extended from that class; this is what you see from the pins labeled As Trigger Box or as FPPCharacter. You typically do this if you have an object that you aren’t sure is of a specific class, so you Cast to verify that it is, and then using the returned object from the node to then perform any class specific actions on that said object.
You know when you’re making a blueprint, you get this dialog
It’s like a tree of different types of things. Actor, is one of the highest things in the tree. If you lookup any blueprint you’ve ever created, it will often be a subclass of actor.
And you’ve probably coded overlap at some point:
It’s only gives you an actor reference. You need some way of knowing, is that one of my blueprints that just walked into the collision volume?
That’s what casting is for. It moves you down the tree.
I’ve casted my bullet actor from my third person character, what is the object here ?
I know what is casting and how it works, I just don’t know what is object pin, what should we put on the object. What’s it’s purpose. That’s all I need to know. So far what I understood is that for example if we cast to our third person character inside my bullet actor, we should put get player character as the object pin as the third person character is a pawn character as mentioned on this picture:
If it was a pawn, I would say get player pawn. If it was controller, get player controller. That’s what I understood about the object.
Sorry if I’m not able to understand well. I’m still struggling to understand some things in unreal.
The Object pin is the object you are wanting to attempt a Cast on. If you want to Cast your character to this Bullet class, then you would need to pin in the ‘self’ variable (you can find this by searching self in the context sensative search in Blueprint) because self is referencing your character since you are in the character Blueprint. Otherwise, you would connect whatever actor variable into this Cast that you want to attempt a Cast on.
I really don’t know how else to explain this, so hopefully this is clear.
I’ve casted my Bullet actor inside of my third person character:
It gave me the error. Because I don’t know what to put on the object.
What you are doing here is casting ‘self’, which is an actor that extends from Character because you are in the ThirdPersonCharacter Blueprint, to the Bullet class. This is not an error, but a warning, because ‘self’ in this instance does not inherit/extend from the Bullet class since ‘self’ is referring to ThirdPersonCharacter, which extends from Character; therefore, would fail as the warning suggests.
Maybe a better question is, which object do you even want to attempt to Cast to Bullet?
Ok, what should I put on the object pin ?
That is a question for you, not me. What object/variable do you want to check is of the class Bullet? Without knowing that, then there is no reason to use Cast and also we cannot really move forward to help you.
Maybe this video will help: [UE4] How to CAST! (Casting to objects and classes) - YouTube
My friend, do you know what should I put on the object pin on the bullet cast ? That’s all I need. Some people on the comments of the video you gave me still struggle with objects. It ain’t me only
I have answered this question for you already: you put into the object pin of the bullet cast an actor or object reference variable of something that you want to check extends from the bullet class. That video I posted does a very good job of explaining it, and I do not know how better to explain it. If you still don’t know, then someone else needs to provide to you a better answer.
Like I said, many moons ago, I don’t think you need to cast. You are spawning the bullet in the same piece of code.
Also, I notice the boolean DIDPAIM, which I assume is an abbreviation of ‘did player aim’. How does a bullet know if the player aimed?
Are you following a tutorial?
Connect the bullet node of your choice with “get actor of class”.