Need help adding Node3D to Nodes Parent via [Tool]

Problem

Need to add a Node3D to the AnimationPlayer’s Parent but it literaly wont work. I even assign the owner of the node it just wont work some one help!

using Godot;
namespace ProjectKazen.Framework;
[GlobalClass]
[Tool]
public partial class FGAnimationPlayer : AnimationPlayer
{
    [Export]
    private Godot.Collections.Array<FGAnimationLibrary> FGAnimationLibraries;
    [Export]
    private Godot.Collections.Array<AnimationLibrary> AnimationLibraries;
    [Export]
    bool ReInit;
    public Node3D HitBoxContainer;
    public string LastAnimation = null;
    public int CurrentAnimationFrame; 
    public FGAnimationLibrary GetFGAnimationLibrary(string LibName)
    {
        foreach(FGAnimationLibrary AnimationLibrary in FGAnimationLibraries)
        {
            if(AnimationLibrary.Name == LibName)
            {
                return AnimationLibrary;
            }
        } 
        return null;
    }
    public void AddFGAnimationLibrary(FGAnimationLibrary AnimationLibrary)
    {
        FGAnimationLibraries.Add(AnimationLibrary);
    }
    public FGAnimationPlayer(){}
    public override void _Ready()
    {
        base._Ready();
        Init();
    }
    public void Init()
    {
        HitBoxContainer = new()
        {
            Owner = GetTree().CurrentScene
        };
        GetParent().CallDeferred("add_child",HitBoxContainer);
        foreach (AnimationLibrary AnimLib in AnimationLibraries)
        {
            AnimationLibrary AnimLibDuplicate = (AnimationLibrary)AnimLib.Duplicate();
            for (int i = 0; i < AnimLibDuplicate.GetAnimationList().Count;i++)
            {
                Animation CurrentAnimation = AnimLibDuplicate.GetAnimation(AnimLibDuplicate.GetAnimationList()[i]);
                for(int j = 0; j < CurrentAnimation.GetTrackCount(); j++)
                {
                    CurrentAnimation.TrackSetInterpolationType(j,Animation.InterpolationType.Nearest);
                }
            }
            AddAnimationLibrary("",AnimLibDuplicate);
        }
    }
    public void SpawnHitBoxes()
    {
        foreach(FGAnimationLibrary FGALib in FGAnimationLibraries)
        {
            foreach(string Animation in FGALib.GetAnimationList())
            {
                FGAnimation FGAnimation = (FGAnimation)FGALib.GetAnimation(Animation);
                //FGAnimation.FightData
            }
        }
    }
    public void ClearAnimations()
    {
        for (int i = 0; i<GetAnimationLibraryList().Count;i++)
        {
            RemoveAnimationLibrary(GetAnimationLibraryList()[i]);
        }
    }
    public override void _Process(double delta)
    {
        base._Process(delta);
        if (ReInit)
        {
            ClearAnimations();
            Init();
            ReInit = false;
        }
        if (IsPlaying())
        {
            CurrentAnimationFrame = (int)(CurrentAnimationPosition * 24 + 0.5f);  
        }
    }
    public void Play()
    {
        base.Play();
    }
}

this is the error btw
E 0:00:01:0645 NativeCalls.cs:486 @ void Godot.NativeCalls.godot_icall_1_55(nint, nint, nint): Invalid owner. Owner must be an ancestor in the tree.
<C++ Error> Condition “!owner_valid” is true.
<C++ Source> scene/main/node.cpp:2113 @ set_owner()
NativeCalls.cs:486 @ void Godot.NativeCalls.godot_icall_1_55(nint, nint, nint)
Node.cs:1143 @ void Godot.Node.SetOwner(Godot.Node)
Node.cs:425 @ void Godot.Node.set_Owner(Godot.Node)
FGAnimationPlayer.cs:39 @ void ProjectKazen.Framework.FGAnimationPlayer.Init()
FGAnimationPlayer.cs:35 @ void ProjectKazen.Framework.FGAnimationPlayer._Ready()
Node.cs:2401 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
AnimationMixer.cs:789 @ bool Godot.AnimationMixer.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
AnimationPlayer.cs:759 @ bool Godot.AnimationPlayer.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
ProjectKazen.Framework.FGAnimationPlayer_ScriptMethods.generated.cs:110 @ bool ProjectKazen.Framework.FGAnimationPlayer.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)

You can’t set the Node.owner before adding the node to the scene tree. You need to do it after.

SceneTree.current_scene is null in the editor. Use EditorInterface.get_edited_scene_root() instead.

What do u mean by editorinterface. Geteditedsceneroot doesnt show up as a function there in that class

I saw it as a function in its singleton instance but it still doesnt work

Could you give more information? The error, the new code, what you want to achieve, the scene structure,…

The error says not valid owner must be ancestor in the scene


And i just want to add a node 3d when ever intithitboxcontainer gets called

Replies do not work for me omg

You are still setting the Node.owner before adding the node to the scene tree which is not possible. Callable.call_deferred() delays the call to the function to idle time and it does not happen at that moment. Set the owner after adding it to the scene tree.

If i dont do call defered i get this message

I know. Create a function that calls add_child() and set the owner and use that function in the call_deferred() call instead.

Holy chezits you fixed it thanks sir I opted to just call inithitboxcontainder in the calldefered function you helped alot thank you!