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

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?

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.

2 Likes

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 :slight_smile:

1 Like

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.

1 Like

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… :slight_smile:

You can create symlinks in windows. ‘mklink’

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? :stuck_out_tongue:

Possibly :slight_smile: 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. :slight_smile:

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.

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.

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. :slight_smile:

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.

2 Likes

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)

1 Like

Ah this may be exactly what I’m looking for. I will look into it. Thanks!

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.

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.

1 Like

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

1 Like

Thank You! This is a big help!