mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
19 lines
546 B
C#
19 lines
546 B
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts;
|
|
|
|
public static class Tools
|
|
{
|
|
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
|
|
{
|
|
if (prefab == null) return null;
|
|
var newInstance = prefab.Instantiate<T>();
|
|
node.GetParent().CallDeferred("add_child", newInstance);
|
|
// Need to use parent instead of owner because tilemap scenes have no owner
|
|
//node.Owner.CallDeferred("add_child", newInstance);
|
|
newInstance.Transform = node.GlobalTransform;
|
|
newInstance.Position = node.Position;
|
|
|
|
return newInstance;
|
|
}
|
|
}
|