Jump to content

Game crashes from spawning enemies


Brutile
 Share

Recommended Posts

My game so far consists of enemies spawning at random locations on a terrain.

After testing half a dozen times, I've found that the game would consistently crash/stop responding after spawning exactly 130 enemies. I've also found that around the 80 mark, some enemies will be invincible. I've done all that I can to prevent memory leaks and after monitoring the memory usage, everything seems in order, but it still crashes after 130 enemies have spawned. Note that there are not 130 enemies alive at the same time, only 20 are allowed to be alive at once, and when they die, their entities and resources are released.

 

Is this likely a fault with my code or is there something in the engine that is causing this?

Link to comment
Share on other sites

Spawning script:

In Start:

enemyModel = Model:Load("Models/Characters/Crawler/crawler.mdl")
enemyModel:Hide()

Spawn Code:

local enemy = Pivot:Create()
enemy:SetScript("Scripts/Objects/AI/Enemy.lua")
enemy.script.player = self.player
enemy:SetPosition(Vec3(math.random(-1000, 1000), 1000, math.random(-1000,1000)), true)

local pick = PickInfo()
local p = enemy:GetPosition()
--places enemy above the terrain
if self.world:Pick(p, Vec3(0, 0, 0), pick, 0.0, true) then
pick.position = pick.position + pick.normal
enemy:SetPosition(pick.position)
end

Enemy Script:

In Start:

--makes an instance of the enemy model in the spawning script
self.playerModel = enemyModel:Instance()
self.playerModel:SetParent(self.entity)
self.playerModel:SetPosition(Vec3(0))
self.playerModel:SetRotation(0, 180, 0)
self.playerModel:SetScale(1.5, 1.5, 1.5)
self.playerModel:Show()

self.entity:SetMass(10)
self.entity:SetPhysicsMode(Entity.CharacterPhysics)
self.entity:SetCollisionType(Collision.Character)
self.entity:SetPickMode(0)

 

Let me know if there is anything else you want to see.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...