【发布时间】:2016-10-04 07:40:30
【问题描述】:
我有两个属性:
UPROPERTY()
TScriptInterface<ICoordinateSystem> CoordinateSystem;
UPROPERTY(EditAnywhere)
TSubclassOf<UCoordinateSystem> CoordinateSystemType;
如何实例化 CoordinateSystemType 并将结果存储到 CoordinateSystem?我尝试过不同的方法,比如
CoordinateSystem = NewObject<ICoordinateSystem>((UObject *) GetTransientPackage(), *CoordinateSystemType);
CoordinateSystem = NewObject<UCoordinateSystem>((UObject *) GetTransientPackage(), *CoordinateSystemType);
CoordinateSystem = Cast<ICoordinateSystem>(NewObject<UCoordinateSystem>((UObject *) GetTransientPackage(), *CoordinateSystemType));
但是它们都没有编译说它不能在 NewObject 或 TScriptInterface = 运算符中将 UObject* 转换为 ICoordinateSystem* 或 ICoordinateSystem* 转换为 UObject*。 我在 UE 4.11 和 4.12 中尝试过
编辑:代码
CoordinateSystem = Cast<ICoordinateSystem>(NewObject<UCoordinateSystem>((UObject *) GetTransientPackage(), *CoordinateSystemType));
我得到错误:
1>------ Build started: Project: UE44X, Configuration: DebugGame_Game x64 ------
1> Creating makefile for UE44X (working set of source files changed)
1> Parsing headers for UE44X
1> Running UnrealHeaderTool "F:\UE4\UE44X 4.12\UE44X.uproject" "F:\UE4\UE44X 4.12\Intermediate\Build\Win64\UE44X\DebugGame\UE44X.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
1> Reflection code generated for UE44X in 4,8843075 seconds
1> Performing 2 actions (4 in parallel)
1> UE44XGameMode.cpp
1>C:\Program Files (x86)\Epic Games\4.12\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h(150): error C2664: 'void FScriptInterface::SetObject(UObject *)': cannot convert argument 1 from 'ICoordinateSystem *' to 'UObject *'
1> C:\Program Files (x86)\Epic Games\4.12\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h(150): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> F:\UE4\UE44X 4.12\Source\UE44X\UE44XGameMode.cpp(26): note: see reference to function template instantiation 'InterfaceType &TScriptInterface<InterfaceType>::operator =<To>(UObjectType *)' being compiled
1> with
1> [
1> InterfaceType=ICoordinateSystem,
1> To=ICoordinateSystem,
1> UObjectType=ICoordinateSystem
1> ]
1> F:\UE4\UE44X 4.12\Source\UE44X\UE44XGameMode.cpp(26): note: see reference to function template instantiation 'InterfaceType &TScriptInterface<InterfaceType>::operator =<To>(UObjectType *)' being compiled
1> with
1> [
1> InterfaceType=ICoordinateSystem,
1> To=ICoordinateSystem,
1> UObjectType=ICoordinateSystem
1> ]
1>ERROR : UBT error : Failed to produce item: F:\UE4\UE44X 4.12\Binaries\Win64\UE44X-Win64-DebugGame.pdb
1> Total build time: 11,90 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3075: The command ""C:\Program Files (x86)\Epic Games\4.12\Engine\Build\BatchFiles\Build.bat" UE44X Win64 DebugGame "F:\UE4\UE44X 4.12\UE44X.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
【问题讨论】:
-
请提供准确的错误信息。
-
它显示:pastebin.com/6BDcmX6W 代码:
CoordinateSystem = Cast<ICoordinateSystem>(NewObject<UCoordinateSystem>((UObject *) GetTransientPackage(), *CoordinateSystemType));
标签: c++ types unreal-engine4