Vector<Sprite3D*> element addChild to another element not working

(redBox is a child of the scene)

Parent and Child relationship Visualized

(Changed variable naming, simplified)

Show us the actual code because a screenshot of code never shows the whole picture. You must have more code than that.

1 Like

clone new greenBox

I suppose, sure but that shouldn’t need to happen.

you can set parent green box

Ideally yes that’s a solution but I have a feeling there is more code than we have been shown here.

Sorry for the late reply and bad English :frowning:
(I simplified the visualization before, so there is a lot more code. I will show it.)

Here is the part of the code. (I modified the names because it was weird.)

redbox is a cocos2d::Sprite3D*, it is a single sprite
yellowBoxVector is a cocos2d::Vector<cocos2d::Sprite3D*>, it contains many sprites
greenBoxVector is a cocos2d::Vector<cocos2d::Sprite3D*>, it contains many sprites


If I use cocos2d::Sprite3D* and not cocos2d::Vector<cocos2d::Sprite3D*>, the bug don’t occur. Is there a way to avoid the bug? (I have to use cocos2d::Vector<cocos2d::Sprite3D*> because I have to contain cloned sprites.)

Am I using the cocos2d::Vector<cocos2d::Sprite3D*> wrong? (I think I am using it wrong.)
Should I post the full code?

How do you clone it? Is there a specific way?
the box is a cocos2d::Sprite3D* (sorry I didn’t write the info)

I’m really sorry for wasting your time :frowning:
I was really dumb, it is not a bug.
It’s just the addChild executed multiple times so it showed the error.

Just a tip, you can also do this to remove it from the parent without actually needing to know which node is the parent:>removeFromParent();

1 Like

Woah, I needed that too!
Thanks for the tip :D

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.