Player Controller Possess Vehicle

It possess but after the vehicle respawn it won’t move. Any idea how to fix this?

SPORTSCAR BP

MY PLAYER CONTROLLER BP

Hey there @BeastNectus! So your widget that houses the buttons likely has a reference to your car/player pawn in there somewhere right? It’s likely that it’s set when it spawns. However you’re spawning a new car after this, so that reference likely needs to be updated, or alternatively you could destroy the old UI and let the car spawning create a new one for you.

To go into specifics I’d have to see what your buttons are bound to.

1 Like

Did you mean this?

You got it.

So basically what’s happening is that when the widget spawns, it looks for a sportscar actor then sets that reference. Problem is that the old UI is trying to send those commands to the old sportscar ref that was there when it was created. You can handle this one of three ways.

  1. Destroy the old UI when you destroy the old car, and let the new one spawn a new UI for it. This is not the most efficient use of Garbage collection, but it will get the job done and decently cleanly.

Or

  1. Have the new car hooked up to the old UI. Which would mean you’d have to make a check to see if the mobile controls are on screen, if so then set the player reference in it to the new car. This would ensure that you don’t have to make a new UI each time and reuse the old ones. This is better on your garbage collector as it doesn’t have to destroy the UI just for a new one to pop up.

Or

  1. Have the car just teleport to the upright position so you don’t have to destroy it. This is usually best as you don’t have to do anything extra fancy, you can keep the old UI and the old functionality of it spawning when you spawn the car, as you won’t be respawning it.

Which one would you like to go for? I can write up an example for whichever one you’d prefer and you can probably adapt it.

1 Like

I like to see the examples each of those for me to get ideas what to do, If it’s okay to you.

I gotcha, let’s run through #3 first since it’s my biggest recommendation. Since you’re working on mobile, the less things you have to garbage collect the better. If it works out we won’t bother with the others, because they are just roundabout ways to do the same thing. I’d only do 1 or 2 if my game really called for it.

So the fun part is all you really change is just not destroying the car. You just teleport the actor to the respawn point and set it’s transform. This will make it inherit the transform of the respawn location, so make sure that’s pointing forward (it probably is considering you’ve been using it like that), and that’s it! Your old UI will remain and the car hasn’t changed. Now if you have car damage and things like that, you may need to reset those values.
image

Try it out, and let me know how it goes!

1 Like

But how can I do that if my CARSREF is class object? Is there another method to do that using my carsref classobject? I think your method is only working for object reference.

image
I set it to class object because I made some blueprint that will show the cars using the class objects. I have 3 cars only.

Sorry! The other image didn’t seem to send.

the return pin from your original spawn will return the actor you created. Use this to set the car reference.

Its working but after spawning the car this happen. The camera is so close.

That is… odd. All that was done was the actor was moved, it shouldn’t effect the camera’s relative distance to the vehicle. Is it clipping something?

What do you mean clipping sir ?

This is all the nodes behind my respawning the car if its flip and not moving.

MyPlayerController BP

SportsCar BP RespawnCheck Function

SportsCar BP EVENT GRAPH

I debug it the reason why its close its because the vehicle scale becomes 1
The vehicle becomes big and that’s why the camera is so close.

This is the scale when its respawning the car.

But I’ve set it my car default scale to 0.5

The problem here is that after respawning the scale of my car becomes 1 instead of 0.5. Any idea to fix this ?

Ahhh yeah, that’s an easy one. So right now it’s inheriting your Respawn Location’s scale. We’ll just break the transform and use a Set Actor Location and Rotation node instead. (you could also just break the pin on the transform one, but this seemed clearer)

1 Like

Thank you it fix my problem. You’re so nice. You explain every step should do. Thanks again.

1 Like