Jump to content

[SOLVED] Unparent Node


photo

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

 

Link to comment

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.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

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
Link to comment
  • morbid changed the title to [SOLVED] Unparent Node
×
×
  • Create New...