Duplicate Full Scene With New Copies of Scripts?

Greetings!

So I have a large, complicated scene for a game which works well and I would like to have additional versions of this scene in the same game, but with scene specific copies of each script (so that they could be heavily modified), the copies being made without losing the established in-editor links.

Since Unity does not allow for multiple scripts with the same name to exist in the same project, this becomes a little harder. In addition, if I change the names of the scripts and internal references, the existing links established in the editor will be lost.

Would it be possible to load each level as an asset bundle after the previous levels containing scripts with identical names are unloaded?

Any help or suggestions would be greatly appreciated. Thanks!:wink:

I don’t think this is possible. But the same ends can usually be achieved with Prefabs and/or proper use of Inheritance.

Thanks for your reply.

I thought about using inheritance but think this will be too messy and require returning to the source-class script for reference, just being a pain in general.

The way I’m pursuing at present is to add a three letter code after the name of each script depending on the scene they’re attached to, and then using an external text file processor to add this code to the end’s of all internal references to other scripts in a particular scene. I would like to write an editor script which would assign all the script references but will most likely use code in the Awake() function of the various scripts to auto-connect to other scripts and objects at runtime.

Thanks again for your reply and any other suggestions would be greatly appreciated.

Inheritance/prefabs would be messier than duplicating a bunch of scripts across scenes???

IMHO, you should reconsider what you are trying to accomplish, because this sounds like a terrible idea.

With Inheritance I would still have to create new scripts with new names for any code changes, correct?

For any overrides, sure. But if you want to make a change to base behaviour, you need only change it in one place, as opposed to N, if you duplicate scripts. Plus, even if you DON’T need code changes, you’ve got duplicate scripts, so…

Most instance/data changes could/should be done at the Inspector/Prefab level.

These are just best practices of good data-driven OOP design, which Unity supports very well.

Yes, but you’d only have to create a new script when needed and managing changes is generally a lot easier. Have you used Inheritance before?

Oh my! Seriously reconsider your approach. Inheritance (wrapping your common code and data into a base class) may sound a bit scary if you’re new to the idea, but it’ll be a Godsend when you need to debug, update, optimize, or extend your code. What you propose usually turns into a nightmare.

With inheritance a base class holds all your common code and data. When you need to change the common code, you typically only need to update that one file.

With your model, when you want to change the common code for N levels, you have to update N files. That’s more work per change and a higher chance of forgetting to fully update one place.

I’ll add, if you create methods and properties with clear purposes and good names, you rarely have to revisit the internals to understand what’s going on. That’s another thing I really enjoy about a good design. :slight_smile:

I understand the benefits of inheritance and am currently using those techniques in another project where there is a lot of commonality betweens scenes. The project the multiple script system is for is a multi-game collection where all of the scenes have a common starting point but need to live in their own little worlds without any interaction. I think the downfall of my current approach will possibly be compile time.

I’m currently writing an editor script which will handle all assignments/linking for the duplicated levels and scripts. All actual script duplication, re-naming, etc will be automated either through editor scripting or external text processing utilities, with each scene having its resources kept in a separate folder. I was hoping Unity would have an easier system such as resource packs which could be loaded/unloaded on a per scene basis (not from the web though), it appears not to be the case though.

Thanks for all your suggestions and I’ll be sure to post how the system works out.