Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Is it bad to have multiple duplicates of prefabs in your project?

Discussion in 'Editor & General Support' started by sickb0y247, Feb 27, 2018.

  1. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    Hello Unity Community!

    The reason I ask is I'd like to organize my prefabs in a particular way. Say I have an office folder that has prefabs of all of the objects you would expect to see in an office setting. And I have other folders like a living room folder with those objects. But there's a chair prefab that could work in both an office setting or a living room per say so I create a duplicate of the prefab and put the chair in both folders. Is this a bad idea? Will it make my project considerably larger or eat up more memory or anything?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your build will load all prefabs into memory that are either in a Resources folder or are referenced in a scene. If you have two different prefabs that are essentially the same prefab, you will be wasting some memory.

    What I would really worry about though is you're creating a situation where it is difficult to maintain your prefabs. Whenever you make a change to one of them you will have to remember to make exactly the same change in the other. That sounds easy, but can become unmanageable in the long run, and introduce unexpected bugs that were easily avoidable.

    I'd do something like this:

    - - Furniture
    - - - - Office Only
    - - - - Home Only

    Place furniture that is only for the office in Office Only, same for Home Only, and place furniture that can be used in both in the root Furniture folder.
     
    Gametyme and sickb0y247 like this.
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    This reminds me that I've thought about this before.. and I kinda wish we could have "fake" links to some assets, just to visually see them (as they apply to more than 1 place.)
    The example listed above is great for a simple folder structure, but some situations could be more complicated ..

    That being said, it's a wishful thinking/random thought I'd have, and I agree with @Joe-Censored 's response about it being much better to do your best at organizing, to avoid the updating issues :)
     
    sickb0y247 likes this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yeah being able to use something like a symlink would certainly be nice for problems like this one. I'm assuming they aren't supported like this though, and I generally work on Windows so can't readily test my assumption.
     
    sickb0y247 likes this.
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I admit I've never tried lol. Lately I haven't really used unity except to help on the forums, so it's not a pressing issue for me.. :)

    You can create symlinks in windows. 'mklink'
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Sigh.... let me guess, mklink has been a part of Windows for like 15 years and I wasn't aware of it until now, right? :p
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Possibly :) I used it many years ago to link eve log folder/files. I then didn't use it forever, until just recently when I linked the asset store download folder of Unity to my external HDD. :)
     
  8. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    Thank you for this. It's a shame it won't work. I also assumed if I changed the original soure prefab it would change all of its duplicates so thank you for clearing that up.

    I wish there was a way. Simply being able to make shortcut references to other prefabs would help a ton with organization.
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm wondering if the nested prefab feature that Unity is rumored to be developing, depending on how it is implemented, may help in this area.
     
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    You know that you can add labels to your project files? Instead of putting these in arbitrary folders, just add labels "office", "living room" and when you edit your office scenes, just search the assets by label "office". No need to over-complicate things. :)

    In case you don't know: just select an asset file in the project window and in the bottom of the inspector window add "asset label". And then you can search for it in the header of the project window (or you can select the appropriate label) -> it works like a folder.
     
    Gametyme and sickb0y247 like this.
  11. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    Duplicating prefab will be loaded twice in memory, but I think that memory is very small and negligible since prefab is just a container. If the underlying resource (like texture, mesh) is the same those will not be doubled. Loading the first prefab will be slow, the second one will take time only for the prefab (should be fast) but not the resources used inside since they are still in the memory.

    But a management problem which you will have to change both prefab in order to update every instance in the game is like other says. Currently I have a Common folder to put things like this. (notably UI elements like buttons, panel)
     
    sickb0y247 likes this.
  12. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    Ah this may be exactly what I'm looking for. I will look into it. Thanks!
     
  13. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    If it doesn't take up much memory or space I may try it. I'm thinking I may take most of my prefabs out of the resource folder entirely. I certainly don't need them all loaded in at once and it would probably help with the duplicate problem. I want a very particular structure that would require a lot of subfolders. Labels might be able to work but if they don't I may try this method.
     
  14. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    No problem, it's cleaner than copying assets around. BTW, to add new label to the pool (like when you can't find the label in the list when you click the blue label icon in the bottom of the inspector window), just type it in the search bar on the top of the popup list and hit enter, it will be added and you will be able to use it to narrow down your assets in the project window after that.

    Also, if you want, you can download the Asset Store Tools asset from the UAS, it contains a "Mass Labeler" tool where you can add/remove labels en masse and you can assign labels to your assets in high number.
     
    Last edited: Mar 1, 2018
    sickb0y247 likes this.
  15. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    ps. I wrote quite a long time ago a comprehensive research about how memory works when it comes to prefabs (and Resources folder, Resources.Load, Unload, etc.). In short I have confirmed that prefab is just a bunch of links that Unity can travel to its resources that needs to be load, but when will Unity loads them depends on various situations. It might be of interest to you : https://gametorrahod.com/unity-texture-memory-loading-unloading-7054819e4ae8
     
    sickb0y247 likes this.
  16. sickb0y247

    sickb0y247

    Joined:
    May 29, 2014
    Posts:
    51
    Thank You! This is a big help!