Download

UProperty is NULL in play mode

Hi,

I am stuck with a problem. I have implemented a custom tank movement component where all the vehicle definition is inside a seperate data asset that can be serialized to json or xml.

In the inspector I can set the tankVehicleData property to a data asset, but as soon as I hit the play button, this property is nulled out.

What am I doing wrong?

Do I have to initialize tankVehicleData with a default object instance which is then overwritten with the inspector data?

Here is the class definition of my custom movement component:


UCLASS( hidecategories = (PlanarMovement, "Components|Movement|Planar", Activation, "Components|Activation"))
class MYPROJECT2_API UTankVehicleMovementComponent : public UWheeledVehicleMovementComponent
{
	GENERATED_BODY()

	USkeletalMeshComponent	*m_Turret;
	USkeletalMeshComponent	*m_TrackLeft;
	USkeletalMeshComponent	*m_TrackRight;
public:

	UPROPERTY(EditAnywhere, Category = GameModeSetup)
		UTankVehicleData* tankVehicleData;


UCLASS()
class MYPROJECT2_API UTankVehicleData : public UDataAsset
{
	GENERATED_BODY()
public:
	/** DragCoefficient of the vehicle chassis. */
	UPROPERTY(EditAnywhere, Category = TankVehicleData)
		float dragCoefficient;

	/** Chassis width used for drag force computation (cm)*/
	UPROPERTY(EditAnywhere, Category = TankVehicleData, meta = (ClampMin = "0.01", UIMin = "0.01"))
		float chassisWidth;

	/** Chassis height used for drag force computation (cm)*/
	UPROPERTY(EditAnywhere, Category = TankVehicleData, meta = (ClampMin = "0.01", UIMin = "0.01"))
		float chassisHeight;

	UPROPERTY(EditAnywhere, Category = TankVehicleData)
		FTankTrackDefinition trackLeft;

	UPROPERTY(EditAnywhere, Category = TankVehicleData)
		FTankTrackDefinition trackRight;
	
	UPROPERTY(EditAnywhere, Category = TankVehicleData)
		FTankTransmissionDefinition transmission;

	UPROPERTY(EditAnywhere, Category = TankVehicleData)
		FTankEngineDefinition engine;

	// Rate at which input throttle can rise and fall
	UPROPERTY(EditAnywhere, Category = VehicleInput, AdvancedDisplay)
		FVehicleInputRate throttleInputRate;

	// Rate at which input brake can rise and fall
	UPROPERTY(EditAnywhere, Category = VehicleInput, AdvancedDisplay)
		FVehicleInputRate brakeInputRate;

	// Rate at which input handbrake can rise and fall
	UPROPERTY(EditAnywhere, Category = VehicleInput, AdvancedDisplay)
		FVehicleInputRate handbrakeInputRate;

	// Rate at which input steering can rise and fall
	UPROPERTY(EditAnywhere, Category = VehicleInput, AdvancedDisplay)
		FVehicleInputRate steeringInputRate;
	
};


Thank you for your help

Eduard

I don’t see anything directly wrong with this. You say you set the vehicle component’s data asset in the inspector, by this you mean in the blueprint defaults?

How do you add the UTankVehicleMovementComponent to your tank actor? Are you doing it in C++, how did you declare the UTankVehicleMovementComponent variable in your actor class (not Transient, right?) and are you by chance recreating it OnConstruction or on BeginPlay?