asqbtcupid / unreal.lua

lua solution for UnrealEngine4
MIT License
300 stars 98 forks source link

How can I spawn a actor in lua? #10

Closed mirchd closed 6 years ago

mirchd commented 6 years ago

Please help, I want to spawn a actor in lua, the cpp class is Inherited from AActor. Thanks.

asqbtcupid commented 6 years ago

look at cmplayercontroller.lua.

function CMPlayerController:SpawnPlayer() 
        local SpawnLocation = FVector.New(0, 0, 300)
         local SpawnRotation = FRotator.New(0,0,0)
         local transfrom = UKismetMathLibrary.MakeTransform(SpawnLocation, SpawnRotation, FVector.New(1, 1, 1))
        local spawnActor = UGameplayStatics.BeginDeferredActorSpawnFromClass(self, self.m_DefaultPawnClass, transfrom, ESpawnActorCollisionHandlingMethod.AlwaysSpawn, self)
        spawnActor = UGameplayStatics.FinishSpawningActor(spawnActor, transfrom)
       self.PlayCharacter = spawnActor
       self.m_PlayCharacter = spawnActor
       spawnActor:SetPlayerController(self)
end
mirchd commented 6 years ago

Thank you very much~