photo

[SOLVED] Unparent Node

Recommended Posts

Hello I have a node within a node hierarchy and I am trying to unparent it by setting Node.SetWorldParent(null)  

My goal is to have the separated node stay in position and not following the parent node. 

If I debug such node Parent is null but node keeps on moving as if attached to parent

Am i missing something ?

thanks

Fred

 

Share this post


Link to post
Posted (edited)

There is another function Node.setParent(), did you try it with this?

Greetings

Edited by ipg_jallmenroeder

Share this post


Link to post

yes I tried both...thanks

Share this post


Link to post

Hello Fred,

Is it C# or C++? Because of capitalizing I thought it's a C#. Anyway, this method works as expected with both.

I tried the simplest way:

C# component:

	private void Init()
	{
		// write here code to be called on component initialization
		Node node = World.GetNodeByName("Sphere"); //It's a parent
		Node node2 = World.GetNodeByName("Cuboid");
		node2.SetWorldParent(null); //Commenting this line causes both nodes to move as expected
	}
	
	private void Update()
	{
		
		node.WorldTranslate(0.0f, 0.1f, 0.0f); // Here I move the parent along Y axis
		
	}

Almost same code in C++:

Unigine::NodePtr node1;
Unigine::NodePtr node2;

AppWorldLogic::AppWorldLogic() {}

AppWorldLogic::~AppWorldLogic() {}

int AppWorldLogic::init()
{
	node1 = World::getNodeByName("material_ball"); //Parent node
	node2 = World::getNodeByName("Cuboid");
	node2->setWorldParent(nullptr);
	return 1;
}

int AppWorldLogic::update()
{
	node1->worldTranslate(0.0f, 0.1f, 0.0f);
	return 1;
}

Could you please share a sample with your code?

Thanks.

Share this post


Link to post
Posted (edited)

Solved, sorry it was my mistake I had to unparent the player not the node itself...

thanks for the quick response!

Fred

 

Edited by fred.naar

Share this post


Link to post