Can’t save asset.
Below is C++ file:
#pragma once
include “CoreMinimal.h”
include “BehaviorTree/BlackboardData.h”
include “ZMBBData.generated.h”
/**
*
*/
UCLASS(BlueprintType)
class ZMCRE4_API UZMBBData : public UBlackboardData
{
GENERATED_BODY()
public:
UZMBBData();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "ZMBBData.h"
#include "BehaviorTree/Blackboard/BlackboardKeyType_Object.h"
#include "BehaviorTree/Blackboard/BlackboardKeyType_Bool.h"
#include "BehaviorTree/Blackboard/BlackboardKeyType_NativeEnum.h"
#include "../ZMEnums.h"
UZMBBData::UZMBBData()
{
// SelfActor - Object(Actor)
{
FBlackboardEntry Entry;
Entry.EntryName = FName("SelfActor");
UBlackboardKeyType_Object* KeyType = NewObject<UBlackboardKeyType_Object>(this, TEXT("SelfActorKeyType"));
KeyType->BaseClass = AActor::StaticClass();
Entry.KeyType = KeyType;
Keys.Add(Entry);
}
// In_Attack_Range - Bool
{
FBlackboardEntry Entry;
Entry.EntryName = FName("InAttackRange");
Entry.KeyType = NewObject<UBlackboardKeyType_Bool>(this, TEXT("InAttackRangeKeyType"));
Keys.Add(Entry);
}
// Zombie_Walking_State - Enum
{
FBlackboardEntry Entry;
Entry.EntryName = FName("ZombieMapState");
UBlackboardKeyType_NativeEnum* KeyType = NewObject<UBlackboardKeyType_NativeEnum>(this, TEXT("ZombieMapStateKeyType"));
KeyType->EnumType = StaticEnum<EZombieMapState>(); // 直接设置枚举类型
KeyType->EnumName = StaticEnum<EZombieMapState>()->GetName();
Entry.KeyType = KeyType;
Keys.Add(Entry);
}
// Dead - Bool
{
FBlackboardEntry Entry;
Entry.EntryName = FName("Dead");
Entry.KeyType = NewObject<UBlackboardKeyType_Bool>(this, TEXT("DeadKeyType"));
Keys.Add(Entry);
}
// Player_Available - Bool
{
FBlackboardEntry Entry;
Entry.EntryName = FName("PlayerAvailable");
Entry.KeyType = NewObject<UBlackboardKeyType_Bool>(this, TEXT("PlayerAvailableKeyType"));
Keys.Add(Entry);
}
}
I create BB_Zombie by Miscellaneous → Data Asset.
Cmd: OBJ SAVEPACKAGE PACKAGE=“/Game/FirstPerson/Blueprints/Enemy/BB_ZombieData” FILE=“../../../../../GameProject/ZMCRe4/Content/FirstPerson/Blueprints/Enemy/BB_ZombieData.uasset” SILENT=true
LogPackageLocalizationCache: Processed 57 localized package path(s) for 2 prioritized culture(s) in 0.014097 seconds
LogSavePackage: Warning: Referencers of BlackboardKeyType_Object /Script/ZMCRe4.Default__ZMBBData:SelfActorKeyType:
LogSavePackage: Warning: ZMBBData /Script/ZMCRe4.Default__ZMBBData (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/AIModule.BlackboardEntry:KeyType
LogSavePackage: Warning: Referencers of BlackboardKeyType_Bool /Script/ZMCRe4.Default__ZMBBData:InAttackRangeKeyType:
LogSavePackage: Warning: ZMBBData /Script/ZMCRe4.Default__ZMBBData (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/AIModule.BlackboardEntry:KeyType
LogSavePackage: Warning: Referencers of BlackboardKeyType_NativeEnum /Script/ZMCRe4.Default__ZMBBData:ZombieMapStateKeyType:
LogSavePackage: Warning: ZMBBData /Script/ZMCRe4.Default__ZMBBData (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/AIModule.BlackboardEntry:KeyType
LogSavePackage: Warning: Referencers of BlackboardKeyType_Bool /Script/ZMCRe4.Default__ZMBBData:DeadKeyType:
LogSavePackage: Warning: ZMBBData /Script/ZMCRe4.Default__ZMBBData (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/AIModule.BlackboardEntry:KeyType
LogSavePackage: Warning: Referencers of BlackboardKeyType_Bool /Script/ZMCRe4.Default__ZMBBData:PlayerAvailableKeyType:
LogSavePackage: Warning: ZMBBData /Script/ZMCRe4.Default__ZMBBData (1 refs)
LogSavePackage: Warning: 0) ObjectProperty /Script/AIModule.BlackboardEntry:KeyType
Warning: Can’t save ../../../../../GameProject/ZMCRe4/Content/FirstPerson/Blueprints/Enemy/BB_ZombieData.uasset: Graph is linked to external private object BlackboardKeyType_Bool /Script/ZMCRe4.Default__ZMBBData:PlayerAvailableKeyType (KeyType)
LogSlate: Window ‘消息’ being destroyed
Message dialog closed, result: Cancel, title: 消息, text: 无法保存资产“/Game/FirstPerson/Blueprints/Enemy/BB_ZombieData”(BB_ZombieData.uasset)。
取消:停止保存所有资产并返回编辑器。
重试:尝试再次保存资产。
继续:仅跳过保存该资产。
LogFileHelpers: InternalPromptForCheckoutAndSave took 4.59 sec
Output messages
adding Keys in the constructor is the problem — NewObject in CDO ctor creates subobjects that reference outer and asset registry tries to serialize KeyType pointers it cant resolve, so Save fails.
instead build keys in PostInitProperties or PostLoad (or lazily on first access), not ctor. BlackboardKeyType subobjects also need to be created with GetTransientPackage outer or CreateDefaultSubobject. for enum, UE 5.x already has BlackboardKeyType_Enum, no need for NativeEnum.
if you really want C+±defined keys, just define arrays in C++ and populate in BP child or override GetBlackboardEntries — DoNotSave assets that came from ctor are usually stale, recreate the asset after moving the code.