Hello im new here. The problem occurs when i want to use my inventory I spawn a pawn and possess it with the default player controller. When I click my item It runs an event through blueprint interface. There are no problem upto the part and the event is running when I call it. The problem occurs when I want to use the item withrespect to my main character. No matter how I try to cast to my main character the cast returns always failed.
Even if I make a variable and reference it to the Main character it fails. I want to know what should I cast to if I want to cast to my orginal character from a different pawn.
I spawn a pawn and possess it with the default player controller
if your spawning in a new pawn and possessing it then your original pawn / character is no longer the player pawn or character. if thats the system your using then the first and third casts shown above would fail. now for the second example which should be the way to go, how are you setting the reference (its not shown here)? what im thinking is your just setting the variables type and not actually getting a reference to the character. to solve this you could use a variable that is exposed on spawn. this would enable you to set the reference from the character when you create the new pawn. though im not really sure why your creating and possessing a new pawn to begin with in this case it doesnt make a lot of sense.
your variables arent the same here ones prot main and the other is player character they are also in different bps. so what your showing in your picture is either not setup to work or its not showing the whole story. whatever bp you want to access the character is the one that needs the reference so probably the widget or the apple in this situation.
hmmm actually try this, in your apple get player pawn and cast to the ui pawn class, then drag off the return pin and then get the player char variable. this will get you the reference you need to target the character though it may be a bit of a roundabout way.
this all may be poorly explained or thought out but forgive me its late here.
Alright I figured it out. I had to make a reference to the Main character in the pawn character blueprint and store its data on a variable created referencing directly to main character. Why this data defaults to zero if i’m referencing it? I hope Unreal makes more documentation explaining casting CLEARLY in their documentation or add an Object reference that can get a pawn directly without going through all the hoops.
Thanks for answering somehow getting a reference to main character gave null value because no object reference in the blueprints works when i reference it directly but when i store a value from the UI_pawn and cast from the Item to the UI_pawn I can access the main character.
casting is pretty simple once you understand what its about. a cast is basically just comparison, asking is this object similar to another know object. imagine you have a car and you dont know the make and model, a cast would be like parking your car next to a mustang and asking are they the same. thats basic casting. now once you get into inheritance things are a bit different, lets say your looking for something of type car meaning 4 wheels and same basic shape. now if you input a mustang it will be true but if you input a plane then it will fail because a plane doesnt have the basic attributes (doesnt inherit) from car.
in your case though you could probably have just saved your reference in the game instance or game mode for easy access and so you dont have to keep setting the reference.
What you are saying is true. But in my case I couldn’t find object type I can cast to in the blueprints. It’s like exorcising a demon if i don’t know the demon’s name (i.e main char reference in possessed chararcter viewpoint).
But saving my reference in the game mode sounds appealing. I’m new to this, I will try that out next time. Thanks a bunch
I had the same problem, and kind of solved it…maybe it also works for u guys~
When u possesses from the main character to a pawn, the controller changes from the charactor to the pawn too, so u can “Get Controller” in the pawn’s BP and then "Cast to PlayerController”, then u can use it as usual~