I have this strange behaviour. I got a C++ class ATankBase that exposes multiple variables
UCLASS()
class TANKGAME_API ATankBase : public AActor
{
GENERATED_BODY()
float m_timeToNextShoot = -1.f;
protected:
UPROPERTY(EditDefaultsOnly)
UBoxComponent* BodyComponent;
UPROPERTY(EditDefaultsOnly)
UBoxComponent* CannonComponent;
UPROPERTY(EditDefaultsOnly)
UBoxComponent* BulletSpawnPoint;
UPROPERTY(EditDefaultsOnly)
float MaxSpeed = 100.f;
UPROPERTY(EditDefaultsOnly)
float MaxCannonRotationSpeed = 30.f;
UPROPERTY(EditDefaultsOnly)
int FireRate = 5;
UPROPERTY(EditDefaultsOnly)
TSubclassOf<class AActor> BulletActor;
UPROPERTY(EditDefaultsOnly)
TSubclassOf<class AActor> ExplosionActor;
UPROPERTY(EditDefaultsOnly)
float MaxLife = 100.f;
float m_currentLife = MaxLife;
public:
UFUNCTION(BlueprintCallable)
void MoveForward(float scale);
UFUNCTION(BlueprintCallable)
void TurnCannon(float scale);
UFUNCTION(BlueprintCallable)
void Fire(float scale);
// Sets default values for this actor's properties
ATankBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
float GetHealth() const;
float GetMaxHealth() const;
};
I extended this class into a BP_TankBase that is where I configure stuff… However from time to time when I open unreal the MaxCannonRotationSpeed , BulletActor, ExplosionActor, and all others get reset to default… this is getting quite frustrating… why is that???
And how do you set in the construction script variables which are in C++ TSubclassOf<> ??? Btw I read about this issue like 3 years old… would be nice if unreal would make things like Saving/Loading work :X
This does not sound like a bug. Unreal will call the constructor of any blueprint actor when it needs to. Since you are setting default values in your C++ class, when you move you move your actor, for example, Unreal will call the constructor again.
Try to uncheck this in your class settings inside the Blueprints editor
It is an old bug of blueprints. Your blueprint is most likely corrupted or something. I had the same problem before and because I couldn’t rewrite the blueprint after awhile I just hardcoded all the variable definitions in the construction script.
That doesn’t make sense. I expect that blueprints also have constructors which by logic should be called after C++ constructors… and I expect that that is the place where the variables get overriden by what I setup in blueprints… I don’t know how hard it is to save a file and not have it corrupt all the time
What you are saying is true. I guess I did not fully understand what your problem was, however, one thing to take into consideration is that UE4 tries to use the Hot Reload feature where applicable, maybe it is not the file that is being corrupted, it is a new one being produced, with the default values.