How can i switch between child pawn classes?

So… the thing starts when i am trying to cast a blueprint child pawn of my main default pawn class and then possessing it and destroying the default pawn. This ticks a neverending list of errors constantly. Besides it doesn’t assign the hud to the new child pawn nor will assign its references in level the blueprint, despite the child pawn its working perfectly when its dragged to the level and its set auto possesed by “Player 0”
I want to be able to switch between 3 pawns wich are all child of the same parent pawn. I am sorry for my english

Post screenshots of how you are doing this.

the references should never work if your changing to a different actor, unless you are resetting them when you posses the new actor. you can avoid some of this by using things like get player character which provides a reference to the character currently possessed. as for the errors i would guess those are a result of the reference problem. the script is probably trying to get information from the first character that you destroyed, but since its destroyed its having errors that it cant fint the needed info. the error your probably getting reads something like “found none trying to access”. course this is all just speculation based on what youve written.

I cannot upload imges, they get stucked at 0%, either image or attachment wont work. But it’s a really simlpe setup, a call of input using the “{” key to “spawn actor from class” returning my child pawn (wich i want to use to replace my main actual parent pawn, using its references) and outputs to a possess node conected to the return value of this last one and my player controller reference. The possessing works just fine, but as for the references (like hud or transforms) it won’t do anything, since my parent pawn is still in the level and its updating the hud with its velocity (its a vehicle). And if i call a “destroy” or “un possess” for the parent this will start ticking errors constantly.
As i said before, if i drag the child pawn to the level and set “auto possess player” as “player 0” it will work perfectly fine. Parent pawn references will work for this child pawn, but i want to do this in runtime

i dont think i can use get player character since this will not reference anything from the parent pawn class,its a vehicle so i think its the same for “get player pawn”. I know i am doing all wrong when i destroy the parent pawn in the level, All i need is to replace the parent pawn with the child pawn on runtime,mantaining its references that’s what i don’t know how to do.

you really need to show us your script so we can see what your attempting to do. from what your saying all your really trying to do is spawn in a new vehicle and have its velocity shown on a widget right (or at least to start with). ok so to do this i would use a get player pawn then get velocity and vector length etc as shown in picture 1 for the binding. you may need to cast if your trying to get a variable or something that is specific but as long as its a variable common to the parent then you can just cast to the parent and have the object in as the get player pawn node. i believe this is part of polymorphism, basically the get player pawn gets a reference to the particular pawn the player is possesing without worrying about class, then you can use a cast to define what class it is only to the extent you need (define it to its parent level). doing a cast is basically like asking is the object like the class im casting (comparing) to. so if you have a ford mustang and you cast it to car then it will be true since the mustang inherits the traits from its parent, ie 4 wheels, basic shape, etc.

the first picture shows how i would create the binding, and the second picture shows how i was testing this. i also just added a third picture to show how you could use a cast to accomplish this as well.

hey, first of all thanks for keep trying to help. I think my problem it’s not the child pawn classes but the respawn thing. The problem starts when i destroy the pawn… if i call a “spawn actor from class” for the same parent pawn i just destroyed it wont change the problem that it’s: 1- update receive draw hud for the new vehicle i just spawn, and: 2- get its transforms (i have a system that keeps adding transforms of the parent pawn to an array and then it uses for set world transform based on set physics linear and angular velocity). so after i respawn none of this either HUD or transforms will work.

1st image is from Parent pawn class: HOLLO
2nd image is from player controller
3rd image is the errors i get after I destroy the pawn. All errors refer to the Vehicle reference in the vehicleHUD, wich is canvas hud, not widget.

the screenshots are all well and good but post one of where the errors are, the hud event graph. all the errors are due to the car being destroyed and the hud trying to read values from it. this tells me the reference isnt being updated in the hud correctly, so thats where we need to start.

the issue is your setting the reference to a variable then using the variable later down the line. This wouldnt be an issue if you werent destroying the pawn, but as you are that means you will need to either not use the variable or you need an event that re-sets the value when you posses a new pawn. THe second option is easy enough, just create a cistom event and plug it into the same place as the begin play. Then after you posses the new pawn just call the event. All you need is a reference to your hud

Thats a really good idea in fact… i will give it a try and come back later… or sooner if this resolves the problem. Thanks again :slight_smile:

I don’t really see the problem :d the next conections are similar to the seen in the second image, all is canvas image and text positioning, some uses calls like rpm string or speed string wich are from vehicle class

So i don’t know how to set your answer as “answer”. Anyway… your are a savior. You were right, calling the new beginplay after posses did the job. I think i wouldn’t figured out by myself. The only problem i still have is a warning of set world transform (i think), even if the flag teleport was already checked.
Thank you so much, i can finally resume the car selection thing i was trying to do. Thank you, and sorry for my english again d:

One more thing. In the level blueprint i created a custom event called Beginplay2 and called it on player controller executing a console command “ce beginplay2” and with that i got my level blueprint references back :slight_smile: