# A Question about Prefabs

**URL:** <https://discussions.unity.com/t/a-question-about-prefabs/665134>\
**Category:** Asset & Content Management\
**Created:** [May 19, 2017, 12:11am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134 "2017-05-19T00:11:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 19, 2017, 12:11am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/1 "2017-05-19T00:11:39Z")

</div>

So, my question is should I really create multiple prefabs for every object?

To give more context, let’s say I am creating Cards.

Well, let’s say there are 300 cards, should I really create 300 prefabs? One for each Card?

Is there a better way to create maybe only a single prefab of a Card, and then when instantiating it, just sets its Sprite, health, attack, resource cost, etc to different values?

That way I don’t have to deal with 300+ prefabs?

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 19, 2017, 3:22am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/2 "2017-05-19T03:22:12Z")

</div>

If you have 300 prefabs of anything, you’re doing something wrong.

It’s definitely better to have a script on a card that can set its textures, health, resources etc… that way you have 1 card and 1 script that manages all that.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 19, 2017, 4:46pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/3 "2017-05-19T16:46:51Z")

</div>

> [@DroidifyDevs](#):
>
> If you have 300 prefabs of anything, you’re doing something wrong.
> 
> It’s definitely better to have a script on a card that can set its textures, health, resources etc… that way you have 1 card and 1 script that manages all that.

Alright, that leads me to my second question I suppose.

I know how to programmatically get the SpriteRenderer of an object and set its current Texture.  
But, I can’t seem to have a TextMesh and a SpriteRenderer on the same object.  
How would I go about displaying a Sprite, and 3+ pieces of text on the same game object?

---

<div class="post-metadata">

**Author:** ![Dreamwriter](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@Dreamwriter](https://discussions.unity.com/u/Dreamwriter)\
**Post date:** [May 19, 2017, 5:07pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/4 "2017-05-19T17:07:27Z")

</div>

Aha, I think I see a misunderstanding. What DroidifyDevs is saying is you create one card prefab - a card object with all the children needed to create its look. That’s how Unity is designed, it’s not really designed to have one GameObject with multiple renderers. When you take that card (with its children) and drag it from the scene into the project, that turns it into a Prefab, and DroidifyDevs is saying it’s not a good idea to create each of the 300 different card types and turn each one into a unique prefab already setup; rather have just the one and change all the bits programmatically as it is spawned.

So for example, after spawning a card, get the child with the name and change the text, get the child with the image and change the sprite texture, etc.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 21, 2017, 1:51am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/5 "2017-05-21T01:51:03Z")

</div>

> [@Dreamwriter](#):
>
> Aha, I think I see a misunderstanding. What DroidifyDevs is saying is you create one card prefab - a card object with all the children needed to create its look. That’s how Unity is designed, it’s not really designed to have one GameObject with multiple renderers. When you take that card (with its children) and drag it from the scene into the project, that turns it into a Prefab, and DroidifyDevs is saying it’s not a good idea to create each of the 300 different card types and turn each one into a unique prefab already setup; rather have just the one and change all the bits programmatically as it is spawned.
> 
> So for example, after spawning a card, get the child with the name and change the text, get the child with the image and change the sprite texture, etc.

Yes, I understand that completely.

My question evolved into more how do I display text and a Sprite on a game object?

---

<div class="post-metadata">

**Author:** ![Dreamwriter](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@Dreamwriter](https://discussions.unity.com/u/Dreamwriter)\
**Post date:** [May 21, 2017, 2:08am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/6 "2017-05-21T02:08:57Z")

</div>

You can’t, Unity is designed to only have one renderer per GameObject. The only way I can think of doing such a thing is to use a RenderTexture, manually compositing a single texture from the text and sprite image yourself. Or you could create a shader that mixes two textures.

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 21, 2017, 3:08am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/7 "2017-05-21T03:08:15Z")

</div>

> [@DylanHolmes](#):
>
> Yes, I understand that completely.
> 
> My question evolved into more how do I display text and a Sprite on a game object?

You can put a World Space Canvas for text and sprites (or Images in the same World Space Canvas) on the object.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 22, 2017, 3:59am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/8 "2017-05-22T03:59:56Z")

</div>

> [@Dreamwriter](#):
>
> You can’t, Unity is designed to only have one renderer per GameObject. The only way I can think of doing such a thing is to use a RenderTexture, manually compositing a single texture from the text and sprite image yourself. Or you could create a shader that mixes two textures.

That seems really cancerous for such a simple idea.

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 22, 2017, 4:37am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/9 "2017-05-22T04:37:55Z")

</div>

> [@DylanHolmes](#):
>
> That seems really cancerous for such a simple idea.

I just told you, have an empty parent object with a script on it, and as a child put on a world canvas. In that world space canvas you can set text, images etc… you can put an image on the world space canvas or make another child sprite object and change its texture. Not too hard, definitely don’t need a custom shader for that.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 22, 2017, 2:34pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/10 "2017-05-22T14:34:09Z")

</div>

> [@DroidifyDevs](#):
>
> I just told you, have an empty parent object with a script on it, and as a child put on a world canvas. In that world space canvas you can set text, images etc… you can put an image on the world space canvas or make another child sprite object and change its texture. Not too hard, definitely don’t need a custom shader for that.

Okay, thank you.

I will try that out and see how it works.

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 23, 2017, 2:04am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/11 "2017-05-23T02:04:51Z")

</div>

> [@DylanHolmes](#):
>
> Okay, thank you.
> 
> I will try that out and see how it works.

Great! If you run into problems, let me know.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 24, 2017, 6:28pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/12 "2017-05-24T18:28:47Z")

</div>

> [@DroidifyDevs](#):
>
> Great! If you run into problems, let me know.

So, I have been busy and haven’t gotten a chance to try out much what you said.

**Edit: I added a “Canvas” Component, and then made its type “World Space”. Ignore the stuff below.**

But, in the Inspect on my Empty GameObject, I press “Add Component”, and then I search for “World…”

And my only results are:

“World Anchor”  
“World Particle Collider (Legacy)”.

Sorry if this is a dumb question, maybe I should just be pointed towards (or find my own) tutorial for World Space Canvases.

**Edit: Now that I have my World Space Canvas added I am a bit confused on how to get text and an image in there, but I will keep playing around with it.**

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 24, 2017, 6:36pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/13 "2017-05-24T18:36:36Z")

</div>

> [@DroidifyDevs](#):
>
> Great! If you run into problems, let me know.

I am sorry I don’t want you to spoon feed me or babysit me.

But, like I said above, I am trying to create cards with Names, Descriptions, Health, Cost, and Attack, as well as a Sprite for each one.

I added a Sprite Renderer to my Canvas (I think), and a Text UI Component. But I can’t seem to position my Text Element, and I can’t add multiple text elements.

---

<div class="post-metadata">

**Author:** ![BlackPete](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/blackpete/32/553207_2.png) [@BlackPete](https://discussions.unity.com/u/BlackPete)\
**Post date:** [May 24, 2017, 11:01pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/14 "2017-05-24T23:01:30Z")

</div>

Don’t add a sprite renderer. Add either an Image or RawImage to the canvas (i.e. right-click on game object → UI → Image). This is UI stuff, so you’ll want to stick with UI components.

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 25, 2017, 11:06pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/15 "2017-05-25T23:06:38Z")

</div>

> [@DylanHolmes](#):
>
> I am sorry I don’t want you to spoon feed me or babysit me.
> 
> But, like I said above, I am trying to create cards with Names, Descriptions, Health, Cost, and Attack, as well as a Sprite for each one.
> 
> I added a Sprite Renderer to my Canvas (I think), and a Text UI Component. But I can’t seem to position my Text Element, and I can’t add multiple text elements.

Do you know how the Canvas system works?

Perhaps try this: [https://unity3d.com/learn/tutorials/topics/user-interface-ui](https://unity3d.com/learn/tutorials/topics/user-interface-ui)

In order to work with the Canvas UI system you need to fully understand how it works. It’ll be a lot easier as you’ll know what to do.

---

<div class="post-metadata">

**Author:** ![DylanHolmes](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@DylanHolmes](https://discussions.unity.com/u/DylanHolmes)\
**Post date:** [May 26, 2017, 2:44am UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/16 "2017-05-26T02:44:42Z")

</div>

> [@DroidifyDevs](#):
>
> Do you know how the Canvas system works?
> 
> Perhaps try this: [https://unity3d.com/learn/tutorials/topics/user-interface-ui](https://unity3d.com/learn/tutorials/topics/user-interface-ui)
> 
> In order to work with the Canvas UI system you need to fully understand how it works. It’ll be a lot easier as you’ll know what to do.

I’ll take a read, and just to be clear: this is for a card that would be on a board (im not sure if that falls under the UI category). Thank you for your help

---

<div class="post-metadata">

**Author:** ![DroidifyDevs](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/droidifydevs/32/340472_2.png) [@DroidifyDevs](https://discussions.unity.com/u/DroidifyDevs)\
**Post date:** [May 26, 2017, 12:11pm UTC](https://discussions.unity.com/t/a-question-about-prefabs/665134/17 "2017-05-26T12:11:30Z")

</div>

> [@DylanHolmes](#):
>
> I’ll take a read, and just to be clear: this is for a card that would be on a board (im not sure if that falls under the UI category). Thank you for your help

That would fall under a World Space canvas. A World Space canvas can be put anywhere in the scene, so it could work.
