Tank Blueprint Barrel Component is Losing Static Mesh Reference Continuously

Hello,

Related to: Tank Blueprint is loosing Barrel continuously

Tank Blueprint Barrel Component is Losing Static Mesh Reference Continuously when re-compiling/reopening the editor.
I’m using Unreal Engine version 4.24.1 and it seems that the bug still occurs.
My solution is to set the Barrel StatisMesh Asset reference on the C++ code:
Create a constructor for the TankBarrel Component and register the static mesh asset there.

TankBarrel.h

public:

    UTankBarrelComponent();

    // -1 is max downward speed and +1 is max upward speed
    void Elevate(float RelativeSpeed);

TankBarrel.cpp

#include "UObject/ConstructorHelpers.h"

UTankBarrelComponent::UTankBarrelComponent()

{
    static ConstructorHelpers::FObjectFinder<UStaticMesh> BarrelAsset(TEXT("/Game/Source/Models/SM_Tank_Barrel"));
    this->SetStaticMesh(BarrelAsset.Object);
    this->SetRelativeLocation(FVector::ZeroVector);
}
4 Likes

Awesome job for posting your solution!

Privacy & Terms