- Home /
How many variables can i have of type 'Prefab' in a scene at one time?
I'm making a game with a lot of items. Things like apples, clothing, and even scene props like trees and houses. I made it so that I have non-3D versions of each item. So when I click on the 3D apple, it disappears and a button labeled "apple" appears in my inventory.
To get this to happen, I needed a prefab of the model I wanted to instantiate to be linked to my player object.(who also has my inventory script)
So the question is, is this a good way to do things? I mean if I have 500 prefabs that are all linked to my player object and all of the prefabs are of the 3D counterparts to my inventory items, would it make my scene lag?
I don't plan to allow there to be too many objects spawned at one time or even when I'm not spawning anything at all, I'm separating my world into parts and loading only the closest parts so that I can not have too many things at once. I'm just worried linking all the objects in the game to my player would be bad. I'm Also making multiple players in a games(online game) So I have considered making this "list" of objects a separate item that only gets loaded once, by the local player, for only the local player. Sorry for typing so much. I'm terrible with words. Thank you for reading! Any advice on this?
That's an idea! Thank you. To be honest, I forgot that unity allowed me to see the current FPS and ram usage of my game. I will definitely try that. If you want to convert to answer I would accept your response.
I'm a little confused by your description of the inventory - are the non 3D versions Sprites? You might setup a little Class / Struct that holds the Sprites and just set the Inventory ones to match up your UI element, only referencing the ones you have.
I have a custom class named Item, all my items are new instances of my item class. they are collected in a List<> and displayed as Buttons. public class Item {public string itemName { get; set; }} Button displays the item.itemName for identification currently.
Answer by Vice_Versa · Aug 10, 2015 at 02:19 AM
I think the best way to find out is to just see how many you can spawn before the fps starts to go down. I think the answer depends on how big the prefabs are
Your answer
Follow this Question
Related Questions
Scripts/buttons getting old (prefab?) values of variables 1 Answer
Increasing through a list after an object has been destroyed 2 Answers
2D Openworld transport game. How to generate the tracks? 0 Answers
Set variables from a prefab 0 Answers
how do variables vs constants work in compiled code? 2 Answers