Game Development Community

Clone Currently Working? [RESOLVED]

by Majicpanda · in Torque Game Builder · 07/11/2012 (11:02 am) · 4 replies

I've seen some past threads on clone working/not working and was wondering what the status was.

I have a simple static sprite on my scene as a background and doing:

%a = background.cloneWithBehaviors() results in t2dSceneGraph::addToScene() - Object '1592' is already in a SceneGraph!.

Is there a different way you're supposed to be doing this? I have tried several of my scene Objects and all result in the same issue and none work with %a.dump() or echo(%a) of any kind.

The idea is I'm trying to create a bunch of "prefab" objects off camera and then clone them when needed so that I can use all their behaviors and properties instead of creating datablocks for everything (which currently works in my latest build but is a lot more cumbersome for designers).

Thanks.

#1
07/12/2012 (11:09 am)
Show us the function/method doing this and some surrounding code.
#2
07/15/2012 (2:02 am)
Some very basic code is to simply drag a sprite object to the scene and name it baseItem.

Here are my console commands.

==>%a = baseItem.cloneWithBehaviors();
t2dSceneGraph::addToScene() - Object '1560' is already in a SceneGraph!.
==>;%a.setPosition(0,0);
(0): Unable to find object: '' attempting to call function 'setPosition'

==>1560.setPosition(0,0); <- works


Also what works is creating a behavior that has:

%template.addBehaviorField(object, "The object to spawn", object, "", t2dSceneObject);

%newObject = %this.object.cloneWithBehaviors();
%newObject.setPosition(0,0);


If you set the object in the editor it works fine, but if you use %this.object = %this in onBehaviorAdd or onLevelLoaded it results in the same unable to find object issue.

EDIT: Is referencing an item by its name possibly not a working method to do cloneWithBehaviors? It seems that the only way to correctly do it currently is to use %this.object.cloneWithBehaviors by directly referencing the object which is possibly the internal name ref? Maybe it doesn't work with "Name" as declared in the builder.
#3
07/16/2012 (10:50 am)
I do a lot of creating "master" objects around the sides, then cloning them. It works fine for me. It shouldn't be that your object is named or anything.

A quick thought: you can get rid of the error you are seeing with by adding this to your gameScripts/main.cs:

$pref::T2D::warnSceneOccupancy = false;

Google for it elsewhere on this forum. Maybe that warning causes the object to not be made? I don't think that is your problem, but it's a start.
#4
07/16/2012 (12:48 pm)
Appears the issue is you cannot clone by the TGB name you specify and store it in a variable. The clone occurs, but it doesn't return anything correctly.

You have to have the internalName reference or pass the object reference in and then clone it. I was trying to do Enemy.cloneWithBehaviors() as an example.. no go.