Skip to content

Commit

Permalink
Fix GameObjectPool
Browse files Browse the repository at this point in the history
  • Loading branch information
kochounoyume committed Jan 1, 2025
1 parent b4046cc commit 39f25ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Packages/MinimalUtility/Runtime/Internal/DontDestroyObject.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
#nullable enable

using System.Runtime.CompilerServices;
using UnityEngine;

namespace MinimalUtility.Internal
{
internal static class DontDestroyObject
{
public static Transform Root => Default.transform;
public static Transform Root
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Shared.transform;
}

public static GameObject Default
public static GameObject Shared
{
get
{
if (s_default == null)
if (s_shared == null)
{
s_default = new GameObject("MinimalUtility." + nameof(DontDestroyObject));
Object.DontDestroyOnLoad(s_default);
s_shared = new GameObject("MinimalUtility." + nameof(DontDestroyObject));
Object.DontDestroyOnLoad(s_shared);
}
return s_default;
return s_shared;
}
}

private static GameObject? s_default;
private static GameObject? s_shared;
}
}
1 change: 1 addition & 0 deletions Packages/MinimalUtility/Runtime/Pool/GameObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void Release(T element)
{
ThrowIfDisposed();
element.gameObject.SetActive(false);
element.transform.SetParent(DontDestroyObject.Root);
_pool.Push(element);
}

Expand Down

0 comments on commit 39f25ec

Please sign in to comment.