Clone a Component

Oct 6, 2010 at 2:57 PM

Hi,

How can i clone a component?

For instance, i want to create a standard model with a custom script.

The only way i made it work is to load another document containing the standard model and the stricpt i want.

Yet, is there any other way to duplicate an existing component without loading another xml?

 

Thanks,

Giannis

Editor
Oct 6, 2010 at 10:20 PM

You could use a list, theyre super awesome for cloning stuff.

if you need to know more let me know and ill put an example up.

-bubzy

Oct 7, 2010 at 2:18 AM

I am not sure i understand how this could work - maybe i didn't explain my problem very well.

Suppose you want on every collision of an object with a block (let's say a standardModel with a script called ExampleScript), this block to be cloned in another position.

Where do you suggest to use the list? Could you give an example?

Thanks in advance,

giannis

 

Editor
Oct 7, 2010 at 7:57 PM

i think you need to define what you want a little better, does the original item stay in existence? does the new item need to have all the same properties as the old one? is there a limit on the items that can be "in play" at one time?

maybe with this info a solution can be found.

but im still thinking lists :D

-bubzy.

Oct 7, 2010 at 9:28 PM

You are right :)

The original item should stay in existence and "act" (update) according to the script that is assigned to.

I want to create another item at runtime which will act independently: think of an enemy in a fps game, which whenever is shot duplicates itself, having all properties the same but be in another position.

Actually, i want to be able to create "infinite" items at runtime. Does the engine provide a way to do this?

The only way i have achieved this is by loading another xml containing the item i want to create, yet i cannot repeat this action since the name of the object created is not unique.

Else, if this is not possible, how can i create at runtime a whole new item, without loading a xml file?

giannis

 

Editor
Oct 7, 2010 at 10:32 PM
Edited Oct 7, 2010 at 10:33 PM

right :p

you need something like

//in declarations

private List<yourscriptnamehere> listname = new List<yourscriptnamehere>();

//in "if shot" function

listname.add(new yourgamename.yourscriptname(engine,DomainName,True)

{

parent = engine.Root,

position = new vector3(x,y,z)

//within this function you can also manipulate other properties within the "new spawn"

});

 

This will "spawn" a new object and add it to the list, it will have its own identity and its own properties, its basically an entirely new object that conforms to the parameters that you set out in your script,  you can perform foreach functions on a list

to make processing all of your objects nice and quick.

 

This is a very basic overview of the list function and is probably wrong. its a built in c# function and help is available from the msdn, but as always if it doesn't make sense or you want more help please ask here.

-bubzy

 

Oct 8, 2010 at 2:03 PM

Well, thanks a lot this pretty much solved my problem. :D

Actually i hadn't noticed an existing constructor in Transfer<Component>, which confused me  :S

 

thanks again for your help :)

giannis