Hello.
So when I’m possessing a vehicle I get errors from my character controller “Access none”
This is so frustrating because I have copied the code from a youtube video and the only difference I can see is that I have a controller blueprint for my controls but in the video the controls are inside the character blueprint…
Any help?
Hi Sune,
You’re seeing ‘Accessed none’ because something is trying to call a function on a reference that is empty/null/unset/undefined.
These errors can be prevented with a ‘Is Valid’ node at which point you could gate the execution of the complaining function until the reference is set. (Alternatively, you could try setting the reference earlier, but since you’re possessing/unpossessing vehicles, this may not be the path forward)
Let us know if you are still having troubles!
Thank you very much for replying.
This solution gets rid of the errors but my car doesn’t want to move D:
I have a BP with my character controller but the car controller is inside the pawn blueprint. What can I do?
Thank you.
When you possess the vehicle, the character pawn is unpossessed from your controller, and the vehicle is possessed. This is a fundamental function of player controllers. And when the character is unpossessed, it’s no longer part of the input chain, so it won’t see the input events. Your input event handling needs to be in the player controller, and forward whatever the actual command are (“move right” or “crouch” or whatever) to the possessed pawn.
When you check “get possessed pawn” in your input event management code, in the player controller, you must figure out whether it’s your regular character, and if so, forward the inputs to that character (e g, AddMovementInput() or Jump() or whatever,) else check if it’s a vehicle, and forward the inputs to the vehicle with whatever functions the vehicle movement controller wants you to use. Typically, using a cast.
What’s extra annoying is that the “on possess” function is only called on server, so you’ll probably want to set up controller actor variables for “possessed character” and “possessed vehicle” and make them OnRep replicated (with notify,) and update them on the server by testing the possessed pawn.
Also, small note: In this particular case, you might not have to cast the controlled pawn, because Add Movement Input is a shared function on the base Pawn class, but once you get into hand-brake for cars versus jumping for characters, weapons, and so on, this pattern will be needed!
You also probably want to clear the variables in the On Unpossess
event handler.