Jump to content

sleeper component schedules wake/sleep test tasks even when entities are offscreen


hoxi
  • Pending

This happens on component creation and/or when assigning a custom sleep/wake test.

Despite these implying this shouldn't be the case, very likely for performance reasons, given how many offscreen entities in the world can be scheduling these tasks:

function Sleeper:OnEntitySleep()
    self:StopTesting()
end

function Sleeper:OnEntityWake()
    self:StartTesting()
end

 

This can simply be addressed by adding a check like this, maybe with an extra one if you do want offscreen sleeping to be a thing for some entities.

function Sleeper:StartTesting(time)
    if self.inst:IsAsleep() then
        return
    end

    if self.isasleep then
        self:SetTest(ShouldWakeUp, time)
    else
        self:SetTest(ShouldSleep)
    end
end

 


Steps to Reproduce
  1. Spawn an entity with a sleeper component offscreen.
  2. Notice how it'll have a sleep/wake test task scheduled.



User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...