How to have multiple scenenodes use the same Entity.

Problems building or running the engine, queries about how to use features etc.
Post Reply
swuth
Bronze Sponsor
Bronze Sponsor
Posts: 53
Joined: Wed Mar 25, 2015 10:01 pm

How to have multiple scenenodes use the same Entity.

Post by swuth »

Hi,

I have instantiated an Entity (lets call it "oTree") . I now want to attach that same "entity" to multiple scenenodes (for instance to generate a quick forest). I tried the following

first I create the entity in my init code.

oTree = OgreRender->m_pSceneMgr->createEntity("tree.mesh");


Then I run this each time I need to add a tree.


{
OgreNodes[node_count]=OgreRender->m_pSceneMgr->getRootSceneNode()->createChildSceneNode();
OgreNodes[node_count]->attachObject(oTree);
OgreNodes[node_count]->setPosition(inmat->posit_x,inmat->posit_y,inmat->posit_z);
node_count++;

}

But Ogre craps out when doing the attach the second time in (node_count = 1). Is this not possible to do? Do I have to generate an Entity for each Tree?

Any advice would be most welcome.

Cheers
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: How to have multiple scenenodes use the same Entity.

Post by scrawl »

An Entity is a MovableObject. MovableObjects can be attached to at most one Node.
Do I have to generate an Entity for each Tree?
Yes. However, all these entities would use the same base Mesh, so there isn't really any duplication.
swuth
Bronze Sponsor
Bronze Sponsor
Posts: 53
Joined: Wed Mar 25, 2015 10:01 pm

Re: How to have multiple scenenodes use the same Entity.

Post by swuth »

Great, thanks! Makes sense I guess.

Cheers
Post Reply