My Authors
Read all threads
Thread about personal #unity packages: I think I've converted most of my Unity stuff now to packages. It's pretty neat, and super easy to reuse, and there's just one copy of each per project. Of course, you need to make sure it works in every project #unitytips (1/?)
So, basically how to convert your code to package: first, you need to have your code isolated with an asmdef. If your code is super-cross-referenced with everything else this might be a headache to make it work. Basically you need to reference everything you are using..
It's suggested that you should name your packages YourName.YourPackage, so that's what I'll do. And we immediately have an error because one of my scripts is using Unity.Mathematics. You need to add it to the asmdef.
If you have your other project scripts refd from the package.. Well.. That won't work. You'll need to have everything refd "packaged".

It's recommended to put runtime code to Runtime folder, and Editor folder to prevent asmdef collision, & also makes it look nicer on git :P
Ok, I'll just make a dummy editor script to show how it works. So, yes, you need to have a SEPARATE asmdef for your editor scripts. Call it YourName.YourPackage.Editor. Make sure that only "Editor" is checked, and reference your runtime asmdef.
Unfortunatelly ,EVERY TIME you modify the asmdef, you have to wait for database refresh which makes this process annoying, also I have a tonne of packages in this project, so that's why it's slow. The less asmdefs the better. I should've probably done this in an empty project :D
Ok, now make a package.json (what I do is I usually just copy an existing one from another package), and lets use this as our params. Make sure to add dependencies. Dependencies will be automatically downloaded. If you use local dependencies, the best is to add them first..
..in case you don't add your local dpnds first, Unity will say "unresolved dependencies", and prevent you from adding the package.
Important thing to note are the .meta files! In case you already have your project already wired up to use these scripts, THEY WILL BE KEPT in the external package as long as you copy the same meta files (as they use GUIDs tied to that file and asmdef).
Ok, we are done with the setup, we can now copy that package outside of our project. I'll put it in my PACKAGES folder. Open a new scene in Unity, now delete that old folder in Assets. Unity will proly be angry and broken now, but don't worry, we'll add the package back!
Ok, now back in our broken project, go to the package manager and in the upper left corner, there's "Add Local Package From Disk". Aaaaaaaaaaaaaaand after 50 seconds there it is! (good thing we now know EXACTLY how slow Unity is) You can now use it, and share with other projects.
..The reason why I said to make a new scene is just so that you don't get "missing scripts" and then you accidentally save which would disrupt GUID connections to the now-packaged scripts.

Well that tutorial took forever. OK, NOW FOR SOME TIPS AND RANTS:
Ofc, the main benefit is you can easily share code with multiple projects. Theoretically, asmdefing your project also makes compilation quicker. Aye say theoretically, because you see there's those database reloads and VS loads slower...
One of the coolest things is now you can git that package separately, and there's no chaos of git submodules/subtrees! The problem of course, is that you need to make sure that updating the scripts will not break it in your other projects. But you can always make a local copy.
Ok, now, the biggest problem that I have with external packages is that I want to ALSO develop them while I work on the project. And, I can't get intellisense to work at all in those detached packages. It's such a slowdown, if anyone has managed to get it working, do tell.
Actually, got it working haha! It's super weird: when you add a package, double click on a script in your project, it will create csproj files for all packages, & to your solution, and now you can use it from there. BUT it DOESN'T work if you do Assets > Open C# Project!
If you do "Open C# Project" it doesn't generate those other csproj files, only generates a single Assembly-CSharp.csproj. Really strange. Also, if your package csproj doesn't appear in the solution for some reason, you can add it with "Add Existing Project".
Ok, that doesn't seem to work in VS Code. csproj files are not recognized, and if someone knows if it is possible to link to the project do tell. I think for this reason (and others) I'm moving back to VS, unfortunately
Another thing that might be problematic is if you have projects in different Unity versions. I had a problem when going from 2018 to 2019, they changed the package system, and meta files in the package got rebuilt. Then when I opened the 2018 project everything was broken...
..But I didn't have that kinda of a problem since a year ago. Right now I'm working in 2019.3 and 2020.1 beta, and all packages work fine.
Ok, I have more tips, but I'm ending the thread here. If you've read everything please like ❤️ this tweet, because the likes drop off exponentially, I can't tell how many people actually reach the end :D Maybe I shouldn't make long threads in the future. Will continue tomorrow!
Correction to weirdness around creating csproj files for packages. That is dependent on your IDE and for VS there's actually an option in preferences to create them! Now it'll work if you open the project either through "Open C# Project" or double clicking on a script.
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Socially Distant Ivan 🌲🏎️💨🌲

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!