为什么在使用Unreal Haxe时我得到一个null的UStaticMeshComponent

时间:2018-02-18 14:17:49

标签: c++ haxe unreal-engine4

我正在尝试使用以下Haxe Unreal插件。 https://github.com/proletariatgames/unreal.hx

我的类似乎没有错误编译但是当我尝试使用FObjectInitializer创建一个UStaticMeshComponent时,我在控制台中跟踪时会看到一个空值。

以下是我在调用CreateDefaultSubobject时用作参考的Haxe Extern

https://github.com/proletariatgames/unreal.hx/blob/9c4b4b512155b76911a06fbad170fd978b0e8ecd/Haxe/Externs/Common/unreal/FObjectInitializer.hx#L9

package unreal;

@:glueCppIncludes("UObject/UObjectGlobals.h")
@:noCopy @:noEquals @:uextern extern class FObjectInitializer {
  public static function Get() : PRef<FObjectInitializer>;

  @:thisConst
  @:noTemplate
  public function CreateDefaultSubobject<T : UObject>(Outer:UObject, SubojectName:FName, ReturnType:UClass, @:opt(ReturnType) ?ClassToCreateByDefault:UClass, bIsRequired:Bool=true, bAbstract:Bool=false, bIsTransient:Bool=false):T;

  @:thisConst
  @:uname("CreateDefaultSubobject")
  @:typeName public function CreateDefaultSubobject_Template<T>(Outer:UObject, SubojectName:FName, bTransient:Bool=false) : PPtr<T>;

  @:thisConst
  @:typeName public function SetDefaultSubobjectClass<T>(SubojectName:FName) : Const<PRef<FObjectInitializer>>;
}

这是我的Haxe Unreal代码。

package fpsgame;

import unreal.*;

@:uclass
@:uname("AFPSObjectiveActor")
class FPSObjectiveActor extends AActor {
    @:uproperty(VisibleDefaultsOnly, BlueprintReadOnly, Category=Mesh, meta=[AllowPrivateAccess="true"])
    var MeshComp:UStaticMeshComponent;
    var SphereComp:USphereComponent;

    public function new(wrapper) {
        super(wrapper);

        var init = unreal.FObjectInitializer.Get();
        MeshComp = init.CreateDefaultSubobject(new TypeParam<UStaticMeshComponent>(), this, new FName("MeshComp"), new TypeParam<UStaticMeshComponent>(), false);
        RootComponent = MeshComp;
        trace(RootComponent);
        // SphereComp = init.CreateDefaultSubobject(new TypeParam<USphereComponent>(), this, new FName("SphereComp"), new TypeParam<USphereComponent>(), false);
        // SphereComp.SetupAttachment(MeshComp);
    }
}

0 个答案:

没有答案