What are TorqueFolders used for?
by Charlie Talley · in Torque X 2D · 09/29/2009 (9:36 am) · 6 replies
As I understand it, once an object is registered with the database, it can be accessed by any GUIControl. In that case, why are objects categorized into TorqueFolders? Is this for rendering purposes (renderer goes down the GUI hiearchy and renders a folder and it's objects sequentially)? Or are TorqueFolders just for easy management of groups of objects?
#2
1. create new folder
2. set the CurrentFolder as root in the object database
3. register new folder
4. set object database's CurrentFolder as the new folder
5. create/load stuff
Does that sound about right?
10/01/2009 (2:35 pm)
Ah ok. That clears up a lot of stuff for me. Any chance there are code samples floating around that shows how to create and use your own folders? I imagine it's something along the lines of :1. create new folder
2. set the CurrentFolder as root in the object database
3. register new folder
4. set object database's CurrentFolder as the new folder
5. create/load stuff
Does that sound about right?
#3
10/01/2009 (4:38 pm)
Yep - that's right:TorqueFolder folder = new TorqueFolder(); TorqueObjectDatabase.Instance.CurrentFolder = TorqueObjectDatabase.Instance.RootFolder; TorqueObjectDatabase.Instance.Register(folder); TorqueObjectDatabase.Instance.CurrentFolder = folder;
#4
10/02/2009 (10:42 am)
Thanks!
#5
2. TorqueObjectDatabase.Instance.RootFolder = TorqueObjectDatabase.Instance.CurrentFolder;
...instead of:
2. TorqueObjectDatabase.Instance.CurrentFolder = TorqueObjectDatabase.Instance.RootFolder;
?
10/02/2009 (8:41 pm)
Isn't it:2. TorqueObjectDatabase.Instance.RootFolder = TorqueObjectDatabase.Instance.CurrentFolder;
...instead of:
2. TorqueObjectDatabase.Instance.CurrentFolder = TorqueObjectDatabase.Instance.RootFolder;
?
#6
Also, RootFolder has no 'setter', because you shouldn't ever be changing the root folder.
10/02/2009 (9:01 pm)
Nope. CurrentFolder is the active folder that TX will automatically put things in. When you Reigister your new Folder it will get nested in whatever folder CurrentFolder is referencing.Also, RootFolder has no 'setter', because you shouldn't ever be changing the root folder.
Torque Owner Duncan Colvin
Also any dynamically create objects that you create after loading the scene will, by default, be added to the scene's folder - so when you unload the scene it also unloads any dynamically created objects as well.
This is pretty useful default behaviour, although it's also possible to explicitly load stuff into particular folders and create your own folders, etc, which can be very useful sometimes.
For example, it is the case that by default TX nests Folders so that if you load scene A and then load scene B, scene B's objects are now in a Folder that is nested inside scene A's folder. If you then unload scene A it will also unload all of scene B's objects. This isn't always what is wanted so it's very handy to be able to get scene B loaded nested inside a different Folder such as the Root Folder so that it is not unloaded when scene A is unloaded.