Some Tips
Some Tips
如果在build时出现cannot open file ... dll
需要把引擎的文件夹的read only
去掉
Hitting D8049 errors when building editor
https://forums.unrealengine.com/t/hitting-d8049-errors-when-building-editor-from-ue4-sln/449409/4
关于UCLASS和UPROPERTY中的设置可以在UnrealEngine\Engine\Source\Runtime\CoreUObject\Public\UObject\ObjectMacros.h
文件中查看。或者直接引用#include "UObject/ObjectMacros.h"
,直接使用UC::
或者UP::
会有提示。
在使用Lambda表达式时,如果会使用到类中的内容时,需要把对象传入,例子:
Cast<UAuraAbilitySystemComponent>(AbilitySystemComponent)
->EffectAssetTags.AddLambda(
[this](const FGameplayTagContainer& AssetTags)
{
for (const FGameplayTag Tag : AssetTags)
{
const FString Msg = FString::Printf(TEXT("GE Tag %s"), *Tag.ToString());
GEngine->AddOnScreenDebugMessage(-1, 8, FColor::Blue, Msg);
GetDataTableRowByTag<FUIWidgetRow>(MessageWidgetDataTable, Tag);
}
});
在一个类中声明Actor
,一定要声明为指针。因为Actor
的构造一定要使用NewObject
。这个类在构造时,也会构造去这个Actor
变量,这里会出现断言。
函数中传入结构体引用时,如下所示:
UFUNCTION(BlueprintCallable)
void SetIsBlockedHit( FGameplayEffectContextHandle& EffectContextHandle, bool bIsBlockedHit);
在蓝图中调用,该引用会在输出节点,如下图:

如果想实现以下效果:

需要在引用前加入UPARAM(ref)
,函数改为如下:
UFUNCTION(BlueprintCallable)
static void SetIsBlockedHit(UPARAM(ref) FGameplayEffectContextHandle& EffectContextHandle, bool bIsBlockedHit);
这段代码,为什么要从数组中取出来的数值,存成本地变量?

因为这里随机数是使用BlueprintPure
,他会在每一次取值时候,都被调用一次,也就是重新随机一次。所以在最右边的红色框中,又取了一次值,所以这里会产生两次随机。
设置自定义Tick
方法,使用FTickFunction
,并可以设置bRunOnAnyThread
让其运行在其他线程。注册该方方法类似:
bool UActorComponent::SetupActorComponentTickFunction(struct FTickFunction* TickFunction)
{
if(TickFunction->bCanEverTick && !IsTemplate())
{
AActor* MyOwner = GetOwner();
if (!MyOwner || !MyOwner->IsTemplate())
{
ULevel* ComponentLevel = (MyOwner ? MyOwner->GetLevel() : ToRawPtr(GetWorld()->PersistentLevel));
TickFunction->SetTickFunctionEnable(TickFunction->bStartWithTickEnabled || TickFunction->IsTickFunctionEnabled());
TickFunction->RegisterTickFunction(ComponentLevel);
return true;
}
}
return false;
}
有时直接复制一个蓝图类会出现不可控的一些问题,所以建议如果需要复制一个蓝图可以直接创建这个蓝图的子类。
FRotator Rotation = (ActorA->GetActorLocation() - ActorB->GetActorLocation()).Rotation();
Rotation.Pitch = 45.f;
const FVector ToTarget = Rotation.Vector();
以上代码的意义是,从B
到A
的向量在Pitch方向旋转45度得到ToTarget
方向向量,且该值是进行了标准化操作。这个也太方便了吧。
这里Rotation
方法其实就是ToOrientationRotator
。
FVector Direction = ActorA->GetActorRotation().Vector();
FVector ForwardVector = GetActorForwardVector();
以上的Direction
与ForwardVector
这两个值是相同的。
可以使用Property Matrix
进行多文件同时操作
在蓝图中减少或避免使用Cast
到一个蓝图类。因为在强转到一个蓝图类时,会把强转的那个类的对象所有的资源都会再加载一边,再cook的时候也会多cook一次。
这里强转一个角色类:

可以看到这个角色类会被引用到:

谨防蓝图与宏中的硬引用
可以使用Redirectors
功能快速热更某项蓝图。
在修改了USkeletalMeshComponent
中的mesh后,如果是有动画蓝图在该组件上。需要重新初始化一下动画蓝图,不然有可能会把已经垃圾处理的mesh姿势加入计算并传入渲染管线,这会造成crash。调用以下方法即可:
BaseMesh->InitAnim(true);
关于第三人称主角旋转设置:

相机旋转:
