Download

How to reset a UPROPERTY to a default value given from the editor on every play?

I have this variable inside a Weapon C++ code:


    UPROPERTY(EditAnywhere,BlueprintReadWrite)
    uint8 AmmoCount;


And the C++ code does


AmmoCount -= 1;

everytime the weapon shoot.

The problem is that, if I set this from the editor let’s say to 50, then I hit Play and shoot 10 times, when I press ESC and go back to the editor, now the actual value in the blueprint has changed to 40.
There is a way to put a default value from the Editor for a UPROPERTY that is not going to change after a play session? (otherwise I have to manually set 50 projectile before hitting Play every time…)

Well, now is actually behaving correctly, so I can only assume I had somehow broken the engine :expressionless:

If changes persist after end play is because you were changing default value instead of instances.

I think that somehow my blueprint got corrupted, in fact if I attempted to do a reload on it, it would even produce an error.

My solution was to delete it and create a new blueprint from the C++, that fixed the problem.

The real question is, how did I broke the blueprint?!