Added BlueprintReadWrite to UProperty but property doesn't change in game when modified by a ticking blueprint

So, currently I am building a wheeled vehicle for my game and I wanted to be able to dynamically change the values of some of the things the the Vehicle Wheel classes that are used to define the wheels. So I jump through the hoops and get Visual Studio and all that up and working. I go to the Vehicle Wheel parent class, the thing that ends in .h or whatever (I don’t know anything about coding at all), and I go down to the property(s) I want to change (Suspension Max Raise, as well as a few others), and I add BlueprintReadWrite in the UPROPERTY() thing. As far as I know, thats all I needed to do. I close the UE4 editor, build my game, open things up, and it all seems to be working. Seems. I can access the properties I wasn’t able to before, but the property i’ve been trying to change doesn’t seem to be actually changing how the Vehicle Wheel class is working. There are no errors in the blueprints, I can see the variable supposedly changing when I attach a ‘Get Suspension Max Raise’ to a print node, but the changes that are supposed to happen in game, aren’t happening. I’m wondering if that Vehicle Wheel class only checks what the value of its variables are at the very start and doesn’t look again. If anyone knows how to fix this, or might have an idea of what is wrong or where I should look at the least, I’d really appreciate the help. Here are some images of the class in VS and the blueprint changing the value on tick.

Everything seems to be set up properly, from what I can tell. Can you tell/show us how you actually use the MaxRaiseValue variable? If you only read it’s value for in-game behavior once (e.g. in BeginPlay), then it obviously won’t reflect changes made to the variable. For changes to the variable to have any effect, you would need to read the value of MaxRaiseValue each tick and re-apply the variable to whatever that value does.

Cheers, Elewyth

Just wanted to add, that Blueprints do not support uint32. Blueprints can only handle uint8, int32 and float :frowning:

I took a quick look into the code: It seems that you’re right. Wheel definitions are imported once during creation of UWheeledVehicleMovementComponent by CreatePhysicsState() method. My advice is to try rerun this procedure after your wheel params change. You can achieve this in two alternative ways:

  1. Navigate to WheeledVehicleMovementComponent.h find line:

    virtual void CreatePhysicsState() override;

add UFUNCTION definition above:

UFUNCTION(BlueprintCallable, Category = "Pawn|Components|WheeledVehicleMovement")
virtual void CreatePhysicsState() override;

This would allow you to call CreatePhysicsState from bluepirnt.

  1. Increment VehicleSetupTag variable from vehicle movement component. To do this you have to make this variable BlueprintReadWrite:

    UPROPERTY(Category = “Pawn|Components|WheeledVehicleMovement”, EditAnywhere, BlueprintReadWrite)
    uint32 VehicleSetupTag;

But i’m not sure if blueprint types can handle uint32. If yes, this should cause physics state update in PreTick method.

Both metods will cause physics state rebuild. The difference is that method one executes exactly when you call itin opposite to method two which triggers physics rebuild during next pretick. Both should work but according to documentation, physics are calculated each frame before tick events (gameplay logic). To sum up: method one is acceptable, method two is correct.

When to use this ? Right after you change tires configuration, if you change tire params every tick, then call this every tick - but this can cause framerate drop. As an alternative, you can use blueprint timer and change tire parameters with longer period.

EDIT:

Elewyth confirmed that blueprints cannot use uint32 type. In this case, you don’t have to add UPROPERTY to VehicleSetupTag variable, you’ll have o modify this variable on the C++ level.
To do this you’ll have to add new BlueprintCallable method in UWheeledVehicleMovementComponent class.

Step1. Add method declaration in Engine\Source\Runtime\Engine\Classes\Vehicles\WheeledVehicleMovementComponent.h

UFUNCTION(BlueprintCallable, Category = "Pawn|Components|WheeledVehicleMovement")
void MarkVehiclePhysicsStateDirty();

Step2. Add method definition in D:\LodowaZatoka\P4_Main\Engine\Source\Runtime\Engine\Private\Vehicles\WheeledVehicleMovementComponent.cpp

void UWheeledVehicleMovementComponent::MarkVehiclePhysicsStateDirty()
{
	VehicleSetupTag++;
}

After you compile that you’ll be able to call MarkVehiclePhysicsStateDirty() method from blueprint :slight_smile:

In that case we should add BlueprintCallable method that will increment this variable on the code side.

Well, I setup everything as you said (though I was a tad confused as to where in the WheeledVehicleMovementComponent I should put each of the thing, I just put them next to other things that looked similar). Unfortunately, the moment the MarkVehiclePhysicsStateDirty is activated, my editor crashes. I have two guesses as to why this might be.

First, I might have added what you told me to add in the wrong place. I don’t know anything about coding so its very possible I put them in the wrong place. I’ll attach screenshots of where I put them so you can see.

Second possibility: When I hover over the Vehicle Movement thing in the components of my boat blueprint, I see that it says it is Wheeled Vehicle Movement Component 4W. I don’t know if that means it is different than the one that doesn’t say 4W, or if it is just a child that inherits info from the version that doesn’t say 4W.

Here are the images of where I put the code you suggested:
The .h file

The .cpp file

Hmm, it doesn’t crash engine on my side. I have UE4.9. I’ve created Advenced Vehicle Example project and use Mark Vehicle… method on X key. Anyway, this seems to reset velocity and gear… I’ll try to investigate this on friday.
Edit:
4W is a child class, so it’s also affected by our change (you were able to call new method). I’ve also checked your screens - they’re correct.

If it would help, I could send you my project file.

Yeah, why not. Pack it with zip, without DerivedDataCache, Saved, Binaries and Intermediate directiries :slight_smile:

Hey, couldn’t find a way to send you a private message here, so sent the project link to your facebook.
Edit: The folder with the current boat I am using is testshipzup4 and the wheels are in test_ship_first_skeleton as frontwheel and backwheel. Kind of a messy file system for my project atm.

Edit: For anyone viewing this, mpo tried out my project in 4.9 (vs 4.8 which is what I am using) and while it doesn’t crash, it resets all physics states, like velocity, gravity to some degree, etc. Results in the car/boat stopping mid air and slowly falling towards ground (at speed slower than it would with gravity). mpo doesn’t think this is the correct avenue to getting adjustable suspension.

Hey, just wondering, would it be possible to limit what the line trace interacts with? Was thinking that it might work out that we wouldn’t have to actually change the Suspension Max Raise if, rather, we put a collision box underneath each wheel, have them linked to the position of each individual wheel, rather than the boat body, and have the line trace only react to objects that are overlapping the collision box. The only thing I would need access to in that case is the line traces themselves in order to limit their interaction. What do you think?