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 overwritten and saved during runtime

Hi. I created custom asset type.

Dialog.h

 UCLASS(BlueprintType, Blueprintable, EditInlineNew)
 class DIALOGSYSTEM_API UDialog : public UObject
 {
     GENERATED_BODY()
 
 public:
     UFUNCTION(BlueprintCallable, Category = "Dialog Object")
         FName GetSpeaker(int id);
 
     UFUNCTION(BlueprintCallable, Category = "Dialog Object")
         FText GetText(int id);
 
     UFUNCTION(BlueprintCallable, Category = "Dialog Object")
         ELinkType GetType(int id);
 
     UFUNCTION(BlueprintCallable, Category = "Dialog Object")
         TArray <int> GetTransitionArray(int id);
 
     UFUNCTION(BlueprintCallable, Category = "Dialog Object")
         TArray <FTransitionConditions> GetArrayOfTransitionConditions(int id);
 
 protected:
     UPROPERTY(EditAnywhere, Category = "My Object Properties")
         TArray <int> openedTransitionsList;
 
     UPROPERTY(EditAnywhere, Category = "My Object Properties")
         TArray <FLink> linkList;
 
 
 private:
 
 };

DialogFactory.cpp

 UDialogFactory::UDialogFactory(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
 {
     UE_LOG(LogTemp, Warning, TEXT("Factory construct"));
     bCreateNew = true;
     bEditAfterNew = true;
     SupportedClass = UDialog::StaticClass();
 }
 
 UObject* UDialogFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
 {
     UE_LOG(LogTemp, Warning, TEXT("Factory create New"));
     auto NewObjectAsset = NewObject<UDialog>(InParent, Class, Name, Flags | RF_Transactional );
     return NewObjectAsset;
 }
 

After

  1. In UserWidget create variable (UDialog Object Referens).

  2. Create asset of UDialog and assign it to variable (DialogContainer) in blueprint.

  3. In Blueprint called GetTransitionArray(int id)

alt text

Function GetTransitionArray(int id) change openedTransitionsList in runtime

Dialog.cpp

 TArray <int> UDialog::GetTransitionArray(int id)
 {
     switch (linkList[id].type)
     {
     case ELinkType::LT_Phrase:
         return linkList[id].transition;
         break;
     case ELinkType::LT_Question:
         {
         for (auto iter = linkList[id].transition.begin(); iter != linkList[id].transition.end(); ++iter)
         {
             openedTransitionsList.AddUnique(*iter);
         }
         return openedTransitionsList;
         }
         break;
     case ELinkType::LT_SpecialQuestion:
         return linkList[id].transition;
         break;
     case ELinkType::LT_Answer:
         return linkList[id].transition;
         break;
     }
     return TArray <int>();
 }

Problem: Changes made to the array (openedTransitionsList) in runtime SAVED in asset. The next time you start the array will be filled to the beginning.

Question: Why? And how to fix it? Why doesn't blueprint create copy of asset for runtime?

Product Version: UE 4.22
Tags:
sqvrwtyffea.jpg (43.3 kB)
more ▼

asked May 24 '19 at 09:45 PM in C++ Programming

avatar image

Greedy Wizard
1 1

(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