Jump to content

Component/Script deactivation


Alienhead
 Share

Recommended Posts

I was doing some thinking on the topic brought up in discord the other day it has me rather bothered...  regarding calling to many components.

I started looking over my own project and realized that 80% of the time component is out of range. Now I do a SetHidden(true) when that happens but If I understand correctly the update() and hooks() still get called?

I have a simple solution, self.entity:DeactivateComponenet(true/false)

For the 100's of objects on a map that arent even being used, seen or reacted with - this seems like a great waste of resource to me. We could simply turn the component OFF so the engine don't make calls to it - then turn it back on when it's in range or whatever the designer sees fit.

I personally,   can see major room for optimization with such an ability

Link to comment
Share on other sites

Let me through out an example.

I have a map with a terrain on it, and plenty of stuff going on, underneath theres a tunnel that goes to a large cave area. Well inside the cave area I have hundreds of scripts/components for doors, particles, etc.etc..  

Now these are constantly getting called ( update() or whatever ) and Im not even in the cave.  It would be easy to build a custom function that checks player distance to component and then re-activate the components when I enter the cave..  

Just an  example... but ..

 

Link to comment
Share on other sites

This is something I have considered. Something like Entity::SetUpdateRange(), and you would need another command to indicate where the "center" of the update region is. It can't just be the camera position, because multiple cameras are supported.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I think it might work right now if you just do this:

function thing:DisableUpdate()
	self.temp = self.Update
	self.Update = nil
end

function thing:EnableUpdate()
	if self.temp ~= nil then self.Update = self.temp end
end

 

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

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...