[unreal] 使用Mixin方案,使用super会出现错误 #930
-
Puerts: Error: (0x0000090B1D6E68F0) call MixinBase_C::ReceiveBeginPlay__puerts_mixin__ of 0000090B5F5AA400 fail:MixinSuperTemplate.js:1:
RangeError: Maximum call stack size exceeded:
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1)
at Object.ReceiveBeginPlay (MixinSuperTemplate.js:1:1) import { blueprint } from "puerts";
import * as UE from "ue";
import { PrintToScreen } from "../../Global/GlobalFunction";
import { ALog } from "../ALabFunctionLibrary";
interface MixinTemp extends UE.Game.ALab.TestMixin.MixinBase.MixinBase_C {}
class MixinTemp {}
class MixinClass extends MixinTemp {
ReceiveBeginPlay(): void {
super.ReceiveBeginPlay();
PrintToScreen("BeginPlay Mixin");
}
}
class MixinSuperTemplate {
//classBaseBP classBaseJS需要保持生命周期同步
classBaseBP: any;
classBaseJS: any;
classDerivedByMixin: any;
constructor() {}
Mixin(path_BP: string): void {
this.classBaseBP = UE.Class.Load(path_BP);
this.classBaseJS = blueprint.tojs<typeof UE.Game.ALab.TestMixin.MixinBase.MixinBase_C>(this.classBaseBP);
Object.setPrototypeOf(MixinTemp.prototype, this.classBaseJS.prototype);
this.classDerivedByMixin = blueprint.mixin(this.classBaseJS, MixinClass);
}
GetDerivedStaticClass(): UE.Class {
if (!this.classDerivedByMixin) {
ALog("Haven't Mixin");
}
return this.classDerivedByMixin.StaticClass();
}
}
export default new MixinSuperTemplate(); 在gamemode里Mixin后通过GetDerivedStaticClass(),spawnActor()。根据示例理解写的,是哪里理解有问题吗 |
Beta Was this translation helpful? Give feedback.
Answered by
chexiongsheng
Jul 28, 2022
Replies: 1 comment 1 reply
-
js调用父类,父类是UE类型,UE的规则是调用子类,于是又调用js,所有死循环。 其次,mixin不是继承,早在mixin出来前继承已经存在几十年了,如果mixin是继承,就没必要折腾个新别名。 我的例子用得也是一个POD类型。 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
aihao2000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
js调用父类,父类是UE类型,UE的规则是调用子类,于是又调用js,所有死循环。
其次,mixin不是继承,早在mixin出来前继承已经存在几十年了,如果mixin是继承,就没必要折腾个新别名。
我的例子用得也是一个POD类型。