x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UObject's Instanced value reset to C++ default value on Play?

Hello everyone,

I'm currently implementing an "Emotion Component" (that inherit from an Actor Component) that have a list of "EmotionGauge" (that inherit from a UObject and FTickableGameObject).

Unfortunately, I'm having a weird problem when I click on the "Play" in the Editor: Some of the value in the EmotionGauge are reset to their default C++ values, and do not take the BP Value into account.

I'll try to be clear as possible: So, I placed a character in my current map, and I'm able to see the default value from C++ correctly: alt text

So now I decide to change these default values in the Character BP: alt text

If I go back to my character in the map I can see that it show the BP value and consider it as the default one: alt text

Now, when I press play, it will get the value from the C++ file, and not from the BP: alt text

Note that if I don't modify the default value in the BP but directly in the instanced character in the map, it takes correctly the value and don't reset it to C++ value

For more info, you can see the implementation below:

So the Emotion Component is an actor component that contains a list of "EmotionGauge", here is the .h:

 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class CROWDBEHAVIOR_API UEmotionComponent : public UActorComponent
 {
     GENERATED_BODY()
 
 public:    
     // Sets default values for this component's properties
     UEmotionComponent();
 
 // ........................
 
 protected:
 
 
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Emotion", Instanced)
     TArray<UEmotionGauge*> EmotionGaugeList;
 
 };

So, now in the constructor, I'm filling the Array by creating several "EmotionGauge", here's the .cpp:

 // Sets default values for this component's properties
 UEmotionComponent::UEmotionComponent()
 {
     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
     // off to improve performance if you don't need them.
     PrimaryComponentTick.bCanEverTick = true;
 
     for (int i = 0; i < (int)EEmotionCategory::COUNT; ++i)
     {
         EEmotionCategory EmotionCategory = (EEmotionCategory)i;
         FString EmotionGaugeName = EnumToString("EEmotionCategory", EmotionCategory) + "Gauge";
 
         UEmotionGauge* NewEmotionGauge = CreateDefaultSubobject<UEmotionGauge>(FName(*EmotionGaugeName));
         EmotionGaugeList.Add(NewEmotionGauge);
     }
 }


So before pressing play, in the BP everything is working fine, the array is filled correctly and for each element I can modify the value contained in the "EmotionGauge", here is EmotionGauge.h:

 UCLASS(BlueprintType)
 class CROWDBEHAVIOR_API UEmotionGauge : public UObject, public FTickableGameObject
 {
 
     GENERATED_BODY()
 
 protected:
     UPROPERTY(EditAnywhere, Category = "Gauge Cooldown")
     bool bDoesValueChangeOverTime = false;
     // In Value/Sec. Represent the speed at which the gauge will tends to the wanted value.
     UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime", ClampMin="0.0"))
     float ModifyingRate = 1.f;
     // Represent the value the gauge will tends to over time.
     UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime"))
     float TargetValueForCooldown = 0.f;
 
     UPROPERTY(EditAnywhere, Category = "Gauge Cooldown", meta = (EditCondition = "bDoesValueChangeOverTime", ClampMin = "0.0"))
     float DelayForTriggeringCooldown = 5.f;
 
 private:
     UPROPERTY(VisibleAnywhere, Category = "Gauge Cooldown")
     float CooldownRemainingDelay = 1.f;
 
 };


Does anyone know what's going on?

Thank you

Product Version: UE 4.22
Tags:
more ▼

asked Jun 13 '19 at 07:32 PM in C++ Programming

avatar image

Albatros155
3 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question