Global" Objects in TGB
by Josias Gibbs · in Torque Game Engine · 08/19/2008 (6:32 pm) · 13 replies
In all the tutorials I've gone through, the only way to spawn an object is to clone an object that already exists in the same level (ie: a "local" object). My question is this: Is there a way to create a "global" object that can be cloned into any level in my game? I have many objects (ie: space ships) that are going to need to be spawned in dozens of different levels (ie: star systems) - and it would be VERY useful to be able to do this.
About the author
#2
The second idea sounds easier (but not nearly as nifty/shiny) - but I'm also not sure how to load a secondary/notRendered scenegraph, or how to add an object to a particular scenegraph - how would I do this (or where's a tutorial that can show me how to do this).
(If I can get this part working, then I think I'll have enough experience points to reach level 4)
08/27/2008 (5:50 pm)
Your first idea sounds like it would be very efficient, but I'm not sure how to define very many of an object's properties in a script - do you (or does anyone) know of a walkthrough or whatnot that could describe how to define most (or all) of an objects properties in a script?The second idea sounds easier (but not nearly as nifty/shiny) - but I'm also not sure how to load a secondary/notRendered scenegraph, or how to add an object to a particular scenegraph - how would I do this (or where's a tutorial that can show me how to do this).
(If I can get this part working, then I think I'll have enough experience points to reach level 4)
#3
You would create a second sceneGraph the same way you would any other object, perhaps in initializeProject would be a good place, example..
new t2dSceneGraph(TemplateObjectGraph);
When you create an object you can specify the sceneGraph "field" and that is the graph it will be added to. Alternatively there are methods in both the sceneGraph and sceneObjects for adding/removing/change the sceneGraph an object is in. Take a look at the above mentioned TGB object reference.
08/27/2008 (6:17 pm)
I'd just look through the TGB documentation, TGB object reference lists all fields. Although they don't usually have documentation with the fields, usually the related "set/get" methods do. Also you can set something in the editor you know how to do, save the level, and go look at the .t2d file to see what it "really" looks like.You would create a second sceneGraph the same way you would any other object, perhaps in initializeProject would be a good place, example..
new t2dSceneGraph(TemplateObjectGraph);
When you create an object you can specify the sceneGraph "field" and that is the graph it will be added to. Alternatively there are methods in both the sceneGraph and sceneObjects for adding/removing/change the sceneGraph an object is in. Take a look at the above mentioned TGB object reference.
#4
This will also allow you to define all the variables you need within the editor. You can also tweak the object in script (managed/persistent.cs).
08/27/2008 (6:30 pm)
@Josias - First and foremost I'd recommend making the objects you want in all or most of your levels persistent. When you flag an object as persistent, it will exist in every scene you create. This will also allow you to define all the variables you need within the editor. You can also tweak the object in script (managed/persistent.cs).
#5
08/27/2008 (7:44 pm)
Doh! Listen to Michael.
#6
08/30/2008 (3:29 pm)
That works great Michael, but I do have one concern - If I create a bunch of persistent spaceship objects in some part of my scenes (ie: way up in the upper right corner for example), then won't any player who flies over to them see a bunch of space ships sitting around in the depths of space? Is there a way to have these template objects be invisible to the player? Or maybe just some way to make sure the player never encounters them?
#7
Or there is a "template" behavior which if you add to an object will set it not-enabled when the level is loaded.
08/30/2008 (3:35 pm)
It sounds like you want to set them not enabled. This will turn off their rendering and physics. There is a checkbox in the editor for "enabled", or from script the field is "enabled" or %obj.setEnabled(true/false). Or there is a "template" behavior which if you add to an object will set it not-enabled when the level is loaded.
#8
08/30/2008 (4:31 pm)
Template behavior is the best bet for now Josias. Have you tried that yet?
#9
09/02/2008 (9:57 am)
I applied the template behavior - and it worked fine, except that it seems to get undone if I set an object to persistent (ie: the template object stays invisible/notEnabled normally, but if that object is set to persistent, then it is no longer invisible) Am I doing something wrong?
#10
Though my theory is this approach doesn't make much sense:
Persistent = exists in every level as an enabled object.
Template = object only exists in editor, and is disabled during actual game play
Hmmm
09/02/2008 (10:19 am)
@Josias - That would be the frustrating bug I've been dealing with for a few weeks. You aren't doing anything wrong. That has to do with how the script files are executed, in terms of priority and overwriting. I haven't found a solution for this, but have brought it up with the TGB devs. Though my theory is this approach doesn't make much sense:
Persistent = exists in every level as an enabled object.
Template = object only exists in editor, and is disabled during actual game play
Hmmm
#11
09/05/2008 (6:39 am)
Hmm... Is there a way to separate the "exists in every level" part from the "enabled object" part (ie: make the object exist in every level without setting it to enabled)? I just want to be able to spawn the bloody thing in every level.
#12
09/05/2008 (8:55 am)
@Josias - That's kind of the problem right now, and I'm working on resolving this in my side project that I work on at home (when not working on documentation).
#13
09/05/2008 (1:34 pm)
Well, if you figure it out, be sure to tell me - it sounds like a tough one.
Associate James Ford
Sickhead Games
$globalObj = new t2dSceneObject() { //..... };If you don't give it a sceneGraph this it will not be deleted when you change/unload levels. Not sure if cloning an object not in a sceneGraph generates any errors, but assuming not, just make sure you add the newly cloned object to the correct sceneGraph at that point.
Alternatively you could put all your "template" objects in one level (if it would be useful to define their characteristics in the editor), and then load that level on a secondary and not rendered sceneGraph. Then the same deal, clone the object and add it to the desired sceneGraph.