Skip to content

Allow RenderTargetStrategy to be shared across prefabs via ScriptableObject? #146

@claytercek

Description

@claytercek

Problem

RenderTargetStrategy is a MonoBehaviour, so it can't be referenced across prefabs in the inspector. This makes sharing a PooledRenderTargetStrategy between panels in different prefabs awkward — you end up needing a scene singleton and a companion component to wire things up at runtime.

Suggestion

A thin RenderTargetStrategyAsset : ScriptableObject that holds pool configuration and manages the lifetime of the underlying runtime component. RivePanel would accept one alongside the existing RenderTargetStrategy field.

  [CreateAssetMenu(...)]
  public class PooledRenderTargetStrategyAsset : RenderTargetStrategyAsset
  {
      [SerializeField] private Vector2Int m_pooledTextureSize;
      [SerializeField] private int m_initialPoolSize;
      [SerializeField] private int m_maxPoolSize;

      private PooledRenderTargetStrategy m_runtimeInstance;

      public override RenderTargetStrategy GetOrCreateStrategy(GameObject host)
      {
          if (m_runtimeInstance != null) return m_runtimeInstance;
          var strategy = host.AddComponent<PooledRenderTargetStrategy>();
          strategy.Configure(m_pooledTextureSize, m_initialPoolSize, m_maxPoolSize, ...);
          m_runtimeInstance = strategy;
          return strategy;
      }
  }

The ScriptableObject stays thin — just config and a factory. The MonoBehaviour still does the actual work, so nothing about LateUpdate batching or render pipeline registration needs to change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions