chexiongsheng / puerts_unreal_demo

unreal demo for puerts
MIT License
178 stars 80 forks source link

撤销C++类的Mixin后没有正常恢复原来的行为 #51

Closed slowmna closed 11 months ago

slowmna commented 11 months ago

定义一个MyActor类,在Tick中调用声明为BlueprintNativeEvent的TestUFun

// UFUNCTION(BlueprintNativeEvent)
// void TestUFun(double DeltaTime);

void AMyActor::TestUFun_Implementation(double DeltaTime)
{
    FRotator Rotator = GetActorRotation();
    SetActorRotation(FRotator(0, Rotator.Yaw + DeltaTime * 30, 0));
}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
    TestUFun(DeltaTime);
    Super::Tick(DeltaTime);
}

再创建一个蓝图类指定父类为刚刚的MyActor,添加一个StaticMesh组件网格体用自带的Cube。保存,然后拖拽蓝图到默认关卡里命名TestMyActor。 此时运行,可以看到TestMyActor在旋转。

编写一个TS脚本TS_Player,并将编译后的蓝图TS_Player拖拽到默认关卡里

import * as UE from 'ue'
import {$ref, $unref, $set, argv, on, toManualReleaseDelegate, releaseManualReleaseDelegate, blueprint} from 'puerts';

class TS_Player extends UE.Character {

    //StaticMesh: UE.StaticMeshComponent;

    Constructor() {
        // this.MixinCPPClass();
    }
    MixinCPPClass(): void {
        const MixinUE = blueprint.tojs<typeof UE.MyActor>(UE.MyActor.StaticClass());
        const MixinTestWithMixin = blueprint.mixin(MixinUE, ExtendMyActor);
    }

    UnMixinCPPClass(): void
    {
        const MixinUE = blueprint.tojs<typeof UE.MyActor>(UE.MyActor.StaticClass());
        const MixinTestWithMixin = blueprint.unmixin(MixinUE);
    }

interface ExtendMyActor extends UE.MyActor {}
class ExtendMyActor {
    ReceiveBeginPlay(): void {
        console.log("ExtendMyActor ReceiveBeginPlay");
    }

    TestUFun(delta : number):void {
        console.log("ExtendMyActor TS TestUFun");
        // this.CallFromTS();
    }
}

export default TS_Player;

可以看到这次执行之后之前的TestMyActor不再旋转了,而是不断的输出“ExtendMyActor TS TestUFun”Log。 然后停止运行后,注释掉TS_Player的Constructor调用MixinCPPClass,再次运行。依旧不转,而且也没有Log输出,断点后发现调用回了C++侧的TestUFun,但是参数和Tick的参数对不上,几乎为0。

试过在停止运行前主动调用UnMixinCPPClass还是有问题。

slowmna commented 11 months ago

提错库了。。。此问题已转提到https://github.com/Tencent/puerts/issues/1618