How can I find how many wheels are on my vehicle?

Hello again everyone,

So I’ve been struggling to get wheels properly working with normal physics bodies. But I have now discovered that there is a WheeledVehicle class and a WheeledVehicleMovementComponent class. However, when I try get the wheels (whether through C++ or through blueprint), they always return zero in length.

As a simple example, I have imported a SkeletalMesh with 10 wheels. For testing, I just setup one wheel (in the Vehicle Setup → Wheel Setups rollout of the Defaults tab for the blueprint, which extends WheeledVehicle) to see if my wheels were returning at least one in length. They did not.

By placing a simple graph on that blueprint (again, I have also done this through C++ as well, as that is how I want to do this), it always return zero for the length. See the image below of the graph.

Is there something that needs to be done to ensure the wheels are initialized?
I have followed this guy’s tutorial down to the T and double checked that everything matches exactly multiple times, and yet I always get zero length, whereas his clearly works in his video. Unreal Engine 4 Vehicle Tutorial (Blueprint) - YouTube

Any help is much appreciate, thank you.

Hi Polygon Byte,

What does your Blueprint’s wheel setups section look like? What about your skeletal mesh and your physics asset (if you don’t mind sharing)? I’m trying to recall if there’s anything integral that I glossed over in the video.

Are you using a WheeledVehicleMovementComponent4W or a WheeledVehicleMovementComponent? According to the engine code (I think), the 4W version will fail to setup the vehicle if the supplied wheel count does not equal 4.

Thank you for the quick reply.

This is what my wheel setup looks like:

As for my Physics Asset, the root node has a single convex hull body instance and each wheel has a single convex hull with linear motion locked (all) and angular motion free (all).

Also, I am using the WheeledVehicleMovementComponent and have also tried it with four wheels, one wheel, and all ten wheels (this will eventually be a ten wheeled tank).

That seems fine, at a glance. Have you tried with more than one wheel setup? Also, do you see anything in your logs? I see a fair amount of wheel setup validation logging in the WheeledVehicleMovementComponent, I’m curious if your setup is getting invalidated during the initialization process.

I’m guessing no given that you’re able to enter play mode and log the tick() override, but I figure it’s worth a look.

Well, this is interesting… I could have sworn that I tried this with four wheels, but it seems I may have not. When I change the wheel setups to encompass only the four outer wheels (front two and rear two), I get the correct length of four returned and the vehicle is actually moving now.

Do you know if there is a way to simulate ten wheels? Granted, a tank technically only has throttle on two wheels anyway. So if I can keep the physics bodies on the inner wheels and still have them turn, then I shouldn’t have a problem even with only four wheels.

I haven’t tried a 10 wheeler but I can give it a shot tonight, I’m curious myself. I would assume that the WheeledVehicleMovementComponent is wheel count agnostic (it appears that it rejects setups with more than 32 wheels or less than 1). I don’t yet understand the engine code well enough to say for sure.

Which WheeledVehicleMovementComponent class are you using?

Try instantiating your vehicle with 4 wheel setups instead of one. Also, make sure you’re using the more generic WheeledVehicleMovementComponent if you don’t intend to use a 4 wheeler; the WheeledVehicleMovementComponent4W class requires that WheelSetups.Num() == 4, and any deviation means the vehicle setup will abort.

So it does appear to be a WheeledVehicleMovementComponent4W. However, when I drop down the Add Components box, WheeledVehicleMovementComponent (both normal and 4W) does not appear in the list even if I search. I tried with both a Blueprint that simply extends WheeledVehicle and my custom C++ class called Tank that extends Wheeled Vehicle as well.

I see what you’re saying. When I create a new blueprint and subclass WheeledVehicle, I automatically get a WheeledVehicleMovementComponent4W.

I haven’t figured out how to change it strictly using blueprints; I would think you could create a C++ class that inherits from WheeledVehicle and then set the VehicleMovement component to an instance of a WheeledVehicleMovementComponent. Then you should be able to implement your vehicle with blueprints or C++ from there with more or less than 4 wheels.

So I’ve tried adding the following to my Tank constructor:

VehicleMovement = PCIP.CreateDefaultSubobject<UWheeledVehicleMovementComponent>(this, TEXT("VehicleMovement"));

However, the editor crashes with this line.

What error does the editor throw when you do that? Did you modify your .h file at all?

Check out the 4.1 default instantiation of a WheeledVehicle here: https://github.com/EpicGames/UnrealEngine/blob/4.1/Engine/Source/Runtime/Engine/Private/WheeledVehicle.cpp#L29. I wonder if you have to set the UpdatedComponent property if you override the VehicleMovement component.

So interestingly enough, if I set my constructor to exactly what is in the WheeledVehicle.cpp (stupid me for not looking at the source code first!):

VehicleMovement = PCIP.CreateDefaultSubobject<UWheeledVehicleMovementComponent, UWheeledVehicleMovementComponent4W>(this, VehicleMovementComponentName);
	VehicleMovement->SetIsReplicated(true); // Enable replication by default
	VehicleMovement->UpdatedComponent = Mesh;

The editor runs perfectly fine but starts with a 4W. However, when I change the component to remove the 4W:

VehicleMovement = PCIP.CreateDefaultSubobject<UWheeledVehicleMovementComponent>(this, VehicleMovementComponentName);
	VehicleMovement->SetIsReplicated(true); // Enable replication by default
	VehicleMovement->UpdatedComponent = Mesh;

The editor then crashes. I’m not really sure where to go with this now or why it’s crashing.

Here is my call stack:

UE4Editor-TankGrounds.dll!FPostConstructInitializeProperties::CreateDefaultSubobject<UWheeledVehicleMovementComponent,UWheeledVehicleMovementComponent>(UObject * Outer, FName SubobjectFName, bool bIsRequired, bool bAbstract, bool bIsTransient) Line 2408	C++

UE4Editor-TankGrounds.dll!ATank::ATank(const FPostConstructInitializeProperties & PCIP) Line 13	C++

And the output:

[2014.05.06-00.30.44:814][  0]LogUObjectGlobals:Warning: Class which was marked abstract was trying to be loaded.  It will be nulled out on save. MovementComp WheeledVehicleMovementComponent
D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.1\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp(1596): Ensure condition failed: false
Class which was marked abstract was trying to be loaded.  It will be nulled out on save. MovementComp WheeledVehicleMovementComponent

I think I’m an idiot! I assume this is failing because WheeledVehicleMovementComponent is an abstract class (https://github.com/EpicGames/UnrealEngine/blob/4.1/Engine/Source/Runtime/Engine/Classes/Vehicles/WheeledVehicleMovementComponent.h#L212) which I believe means that it cannot be used to instantiate a component without the presence of an inheriting class.

It looks like there’s explicit validation to prevent the construction of a component from an abstract class, if I’m reading this correctly: https://github.com/EpicGames/UnrealEngine/blob/4.1/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp#L1589

I think if you wanted to you could create something like UWheeledVehicleMovementComponent10W (or NW), inheriting from UWheeledVehicleMovementComponent. You could then modify the explicit 4W implementation details. I don’t know the engine or PhysX well enough to do this. I see references to classes like PxVehicleDifferential4WData so I suspect you’d have to dig through some of the PhysX vehicle API documentation to do something like this.

My suggestion would be to the stick to the 4 wheeler for your tank and animate the remaining wheels accordingly. You could probably group the wheel bone animations together such that neighboring wheels were animated identically to one another.

I know that a lot of vehicle improvements are coming in the 4.2 release so perhaps it will be possible to have non 4-wheelers very shortly.

That makes sense, the design of an abstract class is usually to prevent direct construction without a non-abstract sub-class. It seems things are working a heck of a lot better even with just four wheels (as opposed to before when I was manipulating fixed physics body instances manually with torque).

I just need to get my acceleration and top speed working tweaked but this is working pretty good so far with the four wheels.

I really appreciate all of your help and especially the speedy replies. Thank you so much! I have marked your answer.

Cool, thanks! I’m happy to help. I also think an Engine developer is going to appear any moment and tell us both what time it is.

Yes, I am sure if I really needed to I could create an extension of the UWheeledVehicleMovementComponent without an issue but as you’ve said, improvements are coming to the vehicles soon (actually that’s the first I’ve heard an actual version number mentioned, so that makes me happy!). For now, I will stick with the 4-wheeler and tweak as needed.

Oddly enough, when I set my steering input, it seems the tank only turns to the left. Definitely lots of tweaks to make but at least I am on the right track now thanks to you!

Make sure your steering axis results in a range of values from -1.0 to 1.0, I found myself with a -1.0 to 0 clamp once that caused that issue.

Please send a screenshot on how you fixed the Wheel issue, i have and i start with 4 wheels and asigned to each bone, yet i get 0 printed.
I did everything as he did int he tutorial: Unreal Engine 4 Vehicle Tutorial (Blueprint) - YouTube
I Read everything here aswell, but 4 wheels doesnt budge with the 4W component… help?
(Blueprints)