How to deParent a GameObject in the Hierarchy using Visual Scripting?

I am trying to unParent a GameObject, and move it into the root of my Hierarchy. I’ve seen various mentions that this C# snippet should do the trick:

GameObject.transform.parent = null;

I tried to create a Visual Scripting version of this C# code here

8253144--1080111--unknown (2).png

But I keep getting the error that “P cannot be Null”.

8253144--1080108--unknown (3).png

Any suggestions how to set the parent of a node to Null using Visual Scripting? Thanks!

I think you need to just leave the node unconnected so it says “None”

When I try that, it gives the same error message?
8254017--1080237--None.png

I must be missing something… just feels like there must be a way to move a Child GameObject into the root of the Unity Hierarchy!

if the script with the unparent action is on the same object you want to unparent, doing this will do the job.
8257926--1080963--upload_2022-7-6_9-48-5.png

This is the one I’m using.
8257926--1080969--upload_2022-7-6_9-49-18.png

If you want to pass an object from a variable, the setup, will look like this.

Yep, that’s exactly how I set it up when I tested it and it worked fine but according to OP it didn’t work for them.

What is OP? Object parent?

@ericb_unity - Thank you for the response! I will try the nodes you sent. My nodes were orange just like yours, and I couldn’t get them to change color.

After losing a few days to this, I decided to just destroy the GameObjects and Instantiate new ones. Glad to hear that you can deparent a Child Node using Visual Scripting!

The issue with your solution if you decide to continue to destroy and instantiate, is that you will generate garbage collection and start to get frames taking lot of time to process.

OP is shorthand for Original Poster, meaning the person who asked the original question.

1 Like

This method worked for me. not sure if this is the same reason his was orange but for me mine was orange when the game wasn’t active because the variable was set somewhere else in my node graph while the game is running.