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
- In UserWidget create variable (UDialog Object Referens).
- Create asset of UDialog and assign it to variable (DialogContainer) in blueprint.
- In Blueprint called GetTransitionArray(int id)
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?