Unreal 蓝图Compile常用API

用途

  • 在蓝图中点击Compile的时候,想做一些事,比如,想自定义逻辑检验当前蓝图逻辑甚至子蓝图是否有异常数据,如果有则返回Compile失败。
  • 点击Compile的时候,想自定义一些逻辑,比如把蓝图中某些数据设置到另外一处,不用手写,通过Compile实现。

用法

确保蓝图数据是否正常

  virtual EDataValidationResult IsDataValid(TArray<FText>& ValidationErrors) override;

根据逻辑动态修改蓝图的值

  FBlueprintCompiledEvent& OnBlueprintCompiled() { return BlueprintCompiledEvent; }

具体案例

xx.h
需要在PostInitProperties注册OnBlueprintCompiled,可以在编译,和每次点击Compile都会执行。

	virtual void PostInitProperties() override;

#if WITH_EDITOR
	FDelegateHandle OnBlueprintCompiledHandle;
	// check res and set name
	void OnBlueprintCompiled();

	virtual EDataValidationResult IsDataValid(TArray<FText>& ValidationErrors) override;
#endif // WITH_EDITOR

xx.cpp中

xx
void xx::PostInitProperties()
{
	Super::PostInitProperties();
	
#if WITH_EDITOR
		if (GEditor)
		{
			OnBlueprintCompiledHandle = GEditor->OnBlueprintCompiled().AddUObject(this, &xx::OnBlueprintCompiled);
		}
#endif // WITH_EDITOR


#if WITH_EDITOR
void xx::OnBlueprintCompiled()
{
	//可以做很多事,编译的时候
}

EDataValidationResult xx::IsDataValid(TArray<FText>& ValidationErrors)
{
  if(true) //可以判断当前的数据
  {
  	  const FString Str = FString::Printf(TEXT("xx Has Same Obj, the type xxx"));
			ValidationErrors.Add(FText::FromString(Str));
			return EDataValidationResult::Invalid; //这样 Compile后返回的是失败,并且显示出来
  }
	return Super::IsDataValid(ValidationErrors);
}
#endif // WITH_EDITOR
}
posted @   不三周助  阅读(91)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示