View Full Version : How to disable a Component or Entity (from being rendered)

01-21-2011, 05:34 AM
I've got a fairly dynamic GUI. Wondering how I can keep some Components/Entities from being rendered at certain times. I'd like to keep them in memory if possible.

01-21-2011, 10:40 AM
Couple of ways.

1. Create your entity hierarchy in such a way that you have two branches that you apply Focuses too.

So you'd do something like (psuedo code here):

AddFocusIfNeeded (pMenu1 (located at RootEntity->GUI->Menu1));
AddFocusIfNeeded (pMenu2 (located at RootEntity->GUI->Menu2));

Now you can do RemoveFocusIfNeeded(pMenu1) to stop rendering, updating, and input processing, and just AddFocus when you want it back. (Keep in mind you can separate those three things if needed)

2. Tell an entity to stop receiving specific recursive function calls - Best?

I think I actually like this method better, so you can be more flexible with the menu layout and not worry about the focus stuff.

Do this to stop rendering of an entity and its children:

#include "Entity/FilterComponent.h"

AddFilter(pButtonEntity, "OnRender"); //add it. Note that optionally we could have sent a third part to set the filter state.
//set it, with optional timeMS to schedule when it should be set
SetFilterSetting(pButtonEntity, "OnRender", Entity::FILTER_REFUSE_ALL, 1000); //turn it off in a second
SetFilterSetting(pButtonEntity, "OnRender", Entity::FILTER_ALLOW, 2000); //turn it back on a second later

This gives you a nice way to stop a whole branch of GUI from rendering. Keep in mind you'd need to also do it for OnUpdate and OnInput if you also want those things killed. (Yeah, I wrote FilterComponent today after I saw your message today.. so you have to update svn to see it :) )

This works because OnRender, OnUpdate, and OnInput are triggered with Entity::CallFunctionRecursivelyWithUpdatedVar() and FilterComponent works by allowing/restricting that recursion on a per-entity basis. (The focus components do the real call, b listening to a slot from BaseApp to figure out when these happen)

3. Well, if it's just a few things, another way is to set the "alpha" property on the entity to 0, so it's invisible.

It's probably still clickable though, but you could fix that problem by setting "disabled" to 1 on the Button2DComponent which will cause it to ignore input. (there is a helper function DisableComponentByName() which makes it easy)

But this method is bad if you have a lot of things because you'd have to do on each entity...