Help with scriptable object usage for my solitaire game

I’m building a solitaire game as a learning project.

I have a prefab called “Card” that represents a generic playing card. It has a box collider and my Card.cs script. It also has 2 child gameObjects, Face and Back. Each child has only a sprite renderer component to display the card image front and back.

I created a scriptable object called CardTemplateSO that contains basic card info like suit and value.

I have created assets of type CardTemplateSO that represents each card in a deck. I.e. Ace of Hearts, etc.

This feels like a good approach but I’m having trouble dynamically instantiating a card prefab and loading the correct CardTemplateSO asset.

I’m using a game manager gameObject to create 52 Card prefabs on load. I’m just not sure how to tell each Card prefab to use the correct CardTemplateSO asset.

Thanks

You would have a component on the card, with a method that accepts this scriptable object and uses that to set up the visuals and everything else. It can also hold onto a reference to the scriptable object, so that can be used to check the card’s value, suite, etc.

You’ll just need to have something that references every card scriptable object (probably in a specific order) to spawn a card prefab for each scriptable object, ergo, each card in a standard deck.