FGameplayTagContainer和FGameplayTag是什么?

ue4中代码

FGameplayTagContainer有两个核心变量,都是存放有FGameplayTag的数组

/** A Tag Container holds a collection of FGameplayTags, tags are included explicitly by adding them, and implicitly from adding child tags */
USTRUCT(BlueprintType, meta = (HasNativeMake = "GameplayTags.BlueprintGameplayTagLibrary.MakeGameplayTagContainerFromArray", HasNativeBreak = "GameplayTags.BlueprintGameplayTagLibrary.BreakGameplayTagContainer"))
struct GAMEPLAYTAGS_API FGameplayTagContainer
{
	GENERATED_USTRUCT_BODY()

	...

	/** Array of gameplay tags */
	UPROPERTY(BlueprintReadWrite, Category=GameplayTags, SaveGame) // Change to VisibleAnywhere after fixing up games
	TArray<FGameplayTag> GameplayTags;

	/** Array of expanded parent tags, in addition to GameplayTags. Used to accelerate parent searches. May contain duplicates in some cases */
	UPROPERTY(Transient)
	TArray<FGameplayTag> ParentTags;

	friend class UGameplayTagsManager;
	friend struct FGameplayTagQuery;
	friend struct FGameplayTagQueryExpression;
	friend struct FGameplayTagNode;
	friend struct FGameplayTag;
	
private:

	/**
	 * DO NOT USE DIRECTLY
	 * STL-like iterators to enable range-based for loop support.
	 */
	
	FORCEINLINE friend TArray<FGameplayTag>::TConstIterator begin(const FGameplayTagContainer& Array) { return Array.CreateConstIterator(); }
	FORCEINLINE friend TArray<FGameplayTag>::TConstIterator end(const FGameplayTagContainer& Array) { return TArray<FGameplayTag>::TConstIterator(Array.GameplayTags, Array.GameplayTags.Num()); }
};

FGameplayTag的部分代码

核心数据是一个FName结构体,可以理解为一个带有一些附加功能的字符串,tag数据以点分字符串的形式存放着

/**
 * A single gameplay tag, which represents a hierarchical name of the form x.y that is registered in the GameplayTagsManager
 * You can filter the gameplay tags displayed in the editor using, meta = (Categories = "Tag1.Tag2.Tag3"))
 */
USTRUCT(BlueprintType, meta = (HasNativeMake = "GameplayTags.BlueprintGameplayTagLibrary.MakeLiteralGameplayTag", HasNativeBreak = "GameplayTags.BlueprintGameplayTagLibrary.GetTagName"))
struct GAMEPLAYTAGS_API FGameplayTag
{
	GENERATED_USTRUCT_BODY()

	...

protected:

	/** Intentionally private so only the tag manager can use */
	explicit FGameplayTag(FName InTagName);

	/** This Tags Name */
	UPROPERTY(VisibleAnywhere, Category = GameplayTags, SaveGame)
	FName TagName;

	friend class UGameplayTagsManager;
	friend struct FGameplayTagContainer;
	friend struct FGameplayTagNode;
};

自己的错误认识:

因为tag是具有层次结构的,所以初次接触到这个东西的时候,便默认为是用map之类的二叉树数据结构来存放,然而查了一通源码之后发现FGameplayTag里面只有一个FName变量。之后在代码中添加打印才知道,原来ue4粗暴的将这个tag直接用字符串的方式存放在FName中...

UE_LOG(LogTemp, Warning, TEXT("*****************************: %s"), *(ContainerTag.GetTagName().ToString()));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值