添加tickactor,没成功

This commit is contained in:
2025-02-12 00:13:16 +08:00
parent 1e0c4b8d8c
commit a9e87c74bb
6 changed files with 132 additions and 21 deletions
+43 -1
View File
@@ -1,4 +1,46 @@
import * as UE from 'ue'
import {argv, blueprint} from 'puerts';
console.log('--------------------------entry.ts started2----------------------')
// 创建一个用于Tick的Actor
class TSTickActor extends UE.Actor {
private lastPrintTime: number = 0;
ReceiveTick(DeltaSeconds: number): void {
super.ReceiveTick(DeltaSeconds);
// 每秒打印一次
this.lastPrintTime += DeltaSeconds;
if (this.lastPrintTime >= 1.0) {
console.log('Tick: ' + this.lastPrintTime.toFixed(2));
this.lastPrintTime = 0;
}
}
// 确保Actor可以Tick
ReceiveBeginPlay(): void {
super.ReceiveBeginPlay();
this.PrimaryActorTick.bCanEverTick = true;
}
}
console.log('--------------------------entry.ts started2----------------------')
// 获取游戏实例和世界
let gameInstance = (argv.getByName("GameInstance") as UE.GameInstance)
let world = gameInstance.GetWorld();
// 在场景中生成TSTickActor
let spawnLocation = new UE.Vector(0, 0, 100); // 在高度100的位置生成,避免卡在地面
let spawnRotation = new UE.Rotator(0, 0, 0);
let spawnTransform = new UE.Transform();
spawnTransform.SetLocation(spawnLocation);
spawnTransform.SetRotation(spawnRotation.Quaternion());
let tickActor = UE.GameplayStatics.BeginDeferredActorSpawnFromClass(
world,
TSTickActor.StaticClass(),
spawnTransform
) as TSTickActor;
UE.GameplayStatics.FinishSpawningActor(tickActor, spawnTransform);
console.log('--------------------------TSTickActor spawned----------------------')