【发布时间】:2021-04-08 16:39:37
【问题描述】:
我正在尝试在虚幻中追踪很多行,我目前正在使用LineTraceSingleByChannel(来自不同的同时线程)执行此操作。但是,我试图切换到AsyncLineTraceByChannel,我想在其中使用FTraceDelegate 在完成时调用函数。我似乎在编译时遇到错误,但我无法找出原因。错误点在第 571 行,这是 FTraceDelegate 的右括号所在的位置(我在代码中对此进行了标记)。
我做错了什么,我该如何解决?
导致错误的代码:
FTraceHandle UAirBlueprintLib::GetObstacleAdvAsync(const AActor* actor, const FVector& start, const FVector& end,
FHitResult& hit, TArray<AActor*>& ignore_actors, ECollisionChannel collision_channel, bool trace_complex, bool get_material)
{
bool bIgnoreSelf = false;
FName traceTag;
FTraceDelegate traceDelegate = FTraceDelegate::CreateWeakLambda(actor, [](const FTraceHandle& handle, FTraceDatum& data)
{
//My logic goes here;
if (data.OutHits.Num() > 0)
{
const FHitResult& Result = data.OutHits[0];
}
});
FCollisionQueryParams trace_params;
trace_params.bReturnPhysicalMaterial = get_material;
trace_params.bTraceComplex = trace_complex;
trace_params.AddIgnoredActors(ignore_actors);
return actor->GetWorld()->AsyncLineTraceByChannel(EAsyncTraceType::Single,
start, end,
collision_channel,
trace_params,
FCollisionResponseParams::DefaultResponseParam,
&traceDelegate);
}
错误:
1>c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateInstancesImpl.h(1008): error C2440: 'return': cannot convert from 'T *' to 'UObject *'
1> with
1> [
1> T=const AActor
1> ]
1> c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateInstancesImpl.h(1008): note: Conversion loses qualifiers
1> c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateInstancesImpl.h(1007): note: while compiling class template member function 'UObject *TWeakBaseFunctorDelegateInstance<UserClass,TTypeWrapper<void> (const FTraceHandle &,FTraceDatum &),FunctorType>::GetUObject(void) const'
1> with
1> [
1> UserClass=const AActor,
1> FunctorType=UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>
1> ]
1> c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateInstancesImpl.h(1019): note: see reference to function template instantiation 'UObject *TWeakBaseFunctorDelegateInstance<UserClass,TTypeWrapper<void> (const FTraceHandle &,FTraceDatum &),FunctorType>::GetUObject(void) const' being compiled
1> with
1> [
1> UserClass=const AActor,
1> FunctorType=UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>
1> ]
1> c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateInstancesImpl.h(1084): note: see reference to class template instantiation 'TWeakBaseFunctorDelegateInstance<UserClass,TTypeWrapper<void> (const FTraceHandle &,FTraceDatum &),FunctorType>' being compiled
1> with
1> [
1> UserClass=const AActor,
1> FunctorType=UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>
1> ]
1> c:\<redacted>\unrealengine\engine\source\runtime\core\public\Delegates/DelegateSignatureImpl.inl(146): note: see reference to class template instantiation 'TWeakBaseFunctorDelegateInstance<UserClass,void (const FTraceHandle &,FTraceDatum &),UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>>' being compiled
1> with
1> [
1> UserClass=const AActor
1> ]
1> C:\<redacted>\Documenten\<redacted>\Unreal\Environments\<redacted>\Plugins\<redacted>\Source\AirBlueprintLib.cpp(571): note: see reference to function template instantiation 'TBaseDelegate<void,const FTraceHandle &,FTraceDatum &> TBaseDelegate<TTypeWrapper<void>,const FTraceHandle &,FTraceDatum &>::CreateWeakLambda<const AActor,UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>,>(UserClass *,FunctorType &&)' being compiled
1> with
1> [
1> UserClass=const AActor,
1> FunctorType=UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>
1> ]
1> C:\<redacted>\Documenten\<redacted>\Unreal\Environments\<redacted>\Plugins\<redacted>\Source\AirBlueprintLib.cpp(564): note: see reference to function template instantiation 'TBaseDelegate<void,const FTraceHandle &,FTraceDatum &> TBaseDelegate<TTypeWrapper<void>,const FTraceHandle &,FTraceDatum &>::CreateWeakLambda<const AActor,UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>,>(UserClass *,FunctorType &&)' being compiled
1> with
1> [
1> UserClass=const AActor,
1> FunctorType=UAirBlueprintLib::GetObstacleAdvAsync::<lambda_628e4b4604e5c1758c2bd3d199f08ff6>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command "C:\<redacted>\UnrealEngine\Engine\Build\BatchFiles\Build.bat -Target="ShaderCompileWorker Win64 Development" -Target="<redacted> Win64 Development -Project=\"C:\<redacted_path>"" -WaitMutex -FromMsBuild" exited with code 5. Please verify that you have sufficient rights to run this command.
【问题讨论】:
-
听起来你在某处缺少
#include,可能是#include "GameFramework/Actor.h" -
感谢您的意见!我尝试了一些不同的包含但没有任何成功。不过,切换到 BindLambda 对我有用。
-
哦,好的,谢谢你告诉我!
标签: c++ unreal-engine4