"Element is already the child of another element" Error

Dec 2, 2010 at 1:56 AM

 

I'm trying to add several 3D models, all the same model, to my scene. The number of 3D models will be dynamic. All the objects are the same but will have independent positions that will change during the lifetime of my app.

So i try to use a List<Mesh> to handle my problem, so i do some like these:

 

_placas.Add(ContentManager.Load<Mesh>("placa.ase"));
_placas.Add(ContentManager.Load<Mesh>("placa.ase"));
   
Scene.AddNode(_placas[0]);
Scene.AddNode(_placas[1]);

 

where _placas are a List<Mesh>.

When I try to compile I have the problem "Element is already the child of another element." 

When I do

 

Mesh placa1 = ContentManager.Load<Mesh>("placa.ase");
Mesh placa2 = ContentManager.Load<Mesh>("placa.ase");
   
Scene.AddNode(placa1);
Scene.AddNode(placa2);

its all ok. 

 

What wrong with the first snipe of code?

Coordinator
Dec 7, 2010 at 8:16 PM

That seems really odd.  I don't see anything wrong with your code. 

What if you try something like this : 

var placa = ContentManager.Load<Mesh>("placa.ase"));
_placas.Add(placa);
_placas.Add(placa.Clone());

Scene.AddNode(_placas[0]);
Scene.AddNode(_placas[1]);

Dec 9, 2010 at 2:34 PM

Its works, using var placa instead Mesh placa... Is odd. Now the objects are blinking. Its normal?

Coordinator
Dec 9, 2010 at 7:58 PM

Blinking.. That sounds odd - is it possible for you to send me the project?  email : einar [at] dolittle [dot] com