[UE4]用C++代码实现蓝图的MoveComponentTo功能

示例:移动摄像机

void AHGameMode::TransfromCamera()
{
	FLatentActionInfo ActionInfo;
	ActionInfo.CallbackTarget = this;
	UKismetSystemLibrary::MoveComponentTo(SelectedHero->GetSpringArm(), FVector(0.f, 0.f, 2000.f), FRotator(-80.f, 0.f, 0.f), false, false, 1.0f, EMoveComponentAction::Move, ActionInfo);
}

注:4.13版本的MoveComponentTo参数增加到了9个:

UKismetSystemLibrary::MoveComponentTo(SelectedHero->GetSpringArm(), FVector(0.f, 0.f, 2000.f), FRotator(-80.f, 0.f, 0.f), false, false, 1.0f, true, EMoveComponentAction::Move, ActionInfo);

 

因为可以设置MoveComponentTo执行过程的时长(比如希望物体不要瞬间移动,而是有一个平滑移动或转向的过程,那么设置其中的时间参数),如果希望执行完毕再回调执行某个函数,再设置下回调的函数名,如果该过程没有暂停操作,则需要将Linkage设为0。例如

 

FLatentActionInfo.ExecutionFunction = "TestCall";
FLatentActionInfo.Linkage= 0;

如果执行后不需要回调函数,必须且只需设置ActionInfo.CallbackTarget = this;即可

 

注意:这里的回调函数TestCall要注明为BlueprintCallable类型

UFUNCTION(BlueprintCallable, Category = "Camera")
		void TestCall();

只有加了UFUNCTION的函数才能利用UE4编译器的反射。

 

API文档:

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UKismetSystemLibrary/MoveComponentTo/index.html

 

猜你喜欢

转载自aigo.iteye.com/blog/2271489