Get Started with Custom Unity Packages (Step by Step)
Vložit
- čas přidán 17. 06. 2024
- Learn how to package your custom code in a modular, version controlled way with Unity Custom Packages, that include Dependency management! Understand the difference between a basic unity packaged Asset and a Custom Unity Package. Today we're taking our Improved Timers code from the previous video and packaging it to share with the community!
FEATURED TOOL:
Smart Editor Tool: assetstore.unity.com/packages...
Jon Skeet on Stack Overflow:
stackoverflow.com/users/22656...
Want to support me? 😀
Buy me a coffee! ko-fi.com/adammyhre
🔔 Subscribe for more Unity Tutorials / @git-amend
Discord: / discord
#unity3d #gamedev #indiedev
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 Two Types of Packages
3:10 Custom Unity Packages
7:20 Assembly Definitions
9:40 Manifest
14:46 Local Packages
Source code: github.com/adammyhre/Unity-Im...
More Useful Code:
github.com/adammyhre?tab=repo...
Unity Utility Library: github.com/adammyhre/Unity-Utils
Lock Inspector Hotkey: gist.github.com/adammyhre/475...
Assets Shown In This Video (Affiliate Links)
Procedural Progress Bar: assetstore.unity.com/packages...
Dungeon Mason Tiny Hero Duo: (FREE): assetstore.unity.com/packages...
Tiny Heroes: assetstore.unity.com/packages...
Tidal Flask Dungeon Pack: assetstore.unity.com/packages...
Hierarchy Icons: assetstore.unity.com/packages...
Better Transform: assetstore.unity.com/packages...
Better Mesh Filter: assetstore.unity.com/packages...
Kyeoms VFX: assetstore.unity.com/publishe...
Follow me!
linktr.ee/gitamend - Hry
Happy Sunday once again! I hope this video helps demystify making custom packages - please post any follow up questions you might have or comments you'd like to share! And of course, please make use of the Improved Timers package in your own projects if you want! 👍
I use my custom packages in private git repos for licensed assets that are cumbersome to import and cannot be shared in public repo. So anybody cloning that repo will see that it has private dependency and the name of that asset.
i use git desktop, seems to do the job and all in a UI system.
This has become the best Unity learning channel on CZcams. There are dozens of tutorials on the basics but this is the only channel with actionable, advanced topics every week. Keep it up!!
Thanks for the kind words! Lots more to come!
The "Quick Recap" part near the end of the video is definitely a great addition to the video format
It's quick & subtle, but totally needed
Yeah, I'm glad I included that. Will probably continue that in the future!
This is 100% getting used today. A lot of my game is sitting in about 5 different projects I have been merging. This is gold for me.
Awesome, let me know how it works out for you.
We are Lucky to have you
Thank you
The biggest take away I got from this, is that Rider has an interface for editing markdown files, and I've been using Notepad all this time. Holy shit.
Haha! Nice isn’t it! I actually discovered that by accident myself a while ago.
"We're gonna rewrite history with a git-amend."
I see what you did there. :U
Hahah.. wasn't intentional, I swear!
you have the highest quality unity tutorials I've seen on CZcams for a long time. Thanks a bunch!
Wow, thanks! Glad you think so! You're welcome.
It was the easiest to understand than any of the Unity 'modular' lectures I learned.
Now I can make my codes into Assets!
Great! Glad to hear that!
@@git-amend I've learned so much from the community you've created, the lectures you've created. You're a giant who shows me the horizon of that far sea through your shoulders.
Thank you always.
Great was looking forward for your video, great topic
Awesome, hope it helps you out!
Great Video! Thank you for sharing. Lots to learn :)
Glad you enjoyed it!
Thanks for the video. It helped understand packages a little better.
Glad it was helpful!
I always wondered how to do this and I got it working right away. Thank you !
Nice, that's what I like to hear!
Dude you rock keep them vids coming!!!!
Thanks!
Awesome video on a great topic. The only thing I would add is that you can start creating your package in a 'Packages' folder, adjacent to the 'Assets' folder. This way you can check how the package works without moving it to another project while still keeping it inside of your project during development.
Great tip! Thanks for sharing that!
Thank you for these videos!! They've been so helpful and motivating.
Every time you surprise me with a topic, I wanted to learn more about.
Again, great video! Keep it up
You are so welcome!
Very nice video, great overview.
There is one thing I missed in the video. Embedded packages. Usually packages are saved in the library package cache folder but they can be moved to project/packages which gives you write access to them (instead of being read only in the cache folder). Of course updates can overwrite your changes so be careful. But that can be hugely useful if you want to modify stuff AND you can actively develop on that package while having unity treat it as a package in the context of the project.
Thanks for the comment. We might cover a few more things that are beyond introduction level in a future video, that's a good thing to point out. Cheers!
Thanks once again Adam! The least I can do is leave a comment:)
You rock!
I always thought this was some sort of black magic that only asset store devs knew. Thanks for sharing!
You're welcome. Publishing on the Store is actually easier than most people think, maybe we'll cover that in a future video.
Thanks for helpful video
Most welcome
Great video as always! Another big gotcha with the UPM is that it cannot currently resolve git dependencies in the package.json only the project manifest. Hopefully they add that feature someday.
Thanks. Yes, I hope so too - that would be fantastic.
Thanks for the video. Would be nice to listen about dependencies from another package in git or local, how to resolve circular dependency of packages, and a few words about UPM.
Also if you use local packages in a team remotely, you required to has them in same path or shared drive.
All great topics - perhaps in a future video.
Thanks for amazing videos, they are priceless, I watch them multiple times so I can fully inject them into my workflow, I really enjoy them, and they make learning these topics enjoyable. By the way I have a question: How would you do an audio system/manager? Which pattern would you use? Thank you
Thank you! The topic of audio management has come up several times. There will be a video about that soon!
great. i see that you have custom script templates where you selected monobehavior scripts, pretty cool
I think that is actually just the default in Unity 6 now... I'll have to double check that.
@@git-amend oh if unity 6 then pretty cool and time saviour.. previously it was just available on rider
Hey Adam, great video and especially useful for my current project :D.
I'm curious about your experience as a developer and with Unity in general.
Also I've been working through your videos whenever I find one useful for my own projects and as a Junior some videos literally took me days to fully understand and iterate on, how long does it actually take you to produce a video and how do you design the code? Because that in general is something we as viewer don't get to see and I always wonder how much time it must've took you to come with the solution we get to see.
Maybe that would even be a good video idea. One dedicated solely on how to build and design unity systems (which would probably become a series of videos because of the complexity^^)
That's a very interesting question! To be honest, it depends on the topic. If it's a topic I'm very familiar with, the amount of research will be low and I'll dogfood a prototype in an hour. I try to start early in the week, so I can iterate on the video idea a few times in the evenings if I have to. The actual recording of a video is the longest part, because recording, audio and video editing are areas I can stand to improve upon - so that takes roughly 8-12 hours on Saturday with breaks here and there. Luckily the subject of the video - code or otherwise - will already be prepared before that, plus I seem to enjoy creating the videos as much as I like programming, so time flies. I agree that systems design and thinking are skills that could be taught here, and we'll get to that too!
@@git-amend Awesome, sounds good! Thanks for the detailed answer and I think system design will be the perfect addition to your design pattern videos. If those videos regarding system design will be just as good as your design pattern videos I honestly think you're literally the ultimate resource for advanced Unity developers
Nice.
i ended up figuring this all out myself a few months ago, knowing how to package your assets is a good way to keep your stuff super organized as well sharing anything with your team or friends becomes a lot easier.
@@damonfedorick Yes, agreed. Thanks for the comment!
Really nice video and easy to understand.
On an other note does your Improved timers still work as expected in a production build after making them a package ?
I have a problem with the [InitializeOnLoadMethod] in different assemblies. My method seems to not be called as i launch my game.
If you faced this problem and have a solution i would really need some insight :)
Don't forget that [InitializeOnLoadMethod] is Editor only. [RuntimeInitializeOnLoadMethod] is for play mode and builds. The ImprovedTimers package does work in a build by the way, just as expected.
@@git-amend Oh yeah it was [RuntimeInitilizeOnLoadMethod] it was just a typo on my question.
Well i try to find why it's not runing on my code. Thanks and keep doing awesome videos :)
Just in time! Thanks a lot! I want to create an extension method library which is using DoTween, Since dotween is a third party asset, what kind of approach should i follow if my package is has dependencies with 3rd assets. As far as i know, we cant create custom packages with 3rd party assets
Sadly, this is still an outstanding issue that Unity has said they are working on, as well as making independent git repositories dependencies. What most people do is explicitly tell users that they have to install XYZ before installing your custom package.
Watch the ending of the video for a pro tip! Worth watching the whole video. (Don't forget to share the video!)
Glad you caught that one!
Great video! The only setback with packages I've experienced is that if you need to modify any of your own imported packages on the fly you'd have to open the original Unity project to do so. This often leads me copy pasting the files instead. Is there any workaround that you know of?
This is a common issue, especially when working in teams where each team is developing different parts but they are dependencies.
One thing you can do as a small developer is try the git subtree command. This lets you have multiple repositories in the same project.
@@git-amend Thanks for the info! I'm not an expert at git, after a bit of digging around I don't quite understand how this would work. Would this mean that there is a dummy wrapper parent repo and the sub repo with the actual code would be editable in all projects?
Using git subtree, you can integrate an external package repository into your main project repository, allowing you to treat the package as part of your project’s codebase. By using commands like git subtree add to include the package and git subtree push to update the package’s upstream repository, you can make and manage changes to the package from within any project that includes it. This approach ensures that updates to the package can be synchronized across multiple projects. Maybe I can try to show this in a video soon since several ppl have asked.
Thanks about mentionin war crimes 🙏
Yes! We can't have that!
Is it possible to add the package dependecies to the exported in a usual way package? I'm wondering because my package on the asset store has a dependency on some of the Unity's packages and I am currently just telling to user "Hey, this is not installed and the package relies on it". Just adding a package.json to the root folder didn't seem to do the trick.
Unfortunately it's not possible to add dependencies to usual way packages or Assets sold on the store. This was a topic a while ago on the Unity forums, but all that came out of that was a suggestion to submit it as an idea for future improvements. I know what you mean though, it's not very user friendly.
forum.unity.com/threads/adding-a-dependency-to-an-asset-store-product-in-a-projects-manifest-json.1108304/
@@git-amend It actually is possible. Idk how I've missed this, but using the "Asset Store Publishing Tools", you can optionally include the project manifest and add UPM packages in the uploader window. It's exactly what I wanted, but it wouldn't work for the asset store packages though. Then you can just export the package on your PC without uploading it into the publisher portal, but there is some overhead because you need a publisher profile.
@@DisturbedOne69 Well that's very interesting, I had no idea. I'll have to look into that. I don't remember ever seeing anything from the Asset Store that included a manifest.
Have you found a way to install from "My assets" eg store bought assets, into projects via code, without importing them as files from the unity cache?
I have yes, use it all the time. There is some sample code that you can check out here, but maybe we'll cover it more in depth in a future video as well. We covered this briefly in the 3D platformer series, as it evolved over several videos. Take a look here:
github.com/adammyhre/3D-Platformer/tree/master/Assets/MyTools
@@git-amend thanks, ive seen so many different things about installing asset store packages, and so far all have failed to work correctly, as yours finds the cache and loads from it - specifically one of the non criteria was not to load from the cache. eg i want it to be the latest version, so to download it if necessary.
Can we add other custom packages as dependencies in package.json? Let's say that my custom package codes are dependent on UniTask how can i overcome this dependency problem?
Unfortunately not at this time. Unity allows you to add Git packages as dependencies in the Project level Manifest file, but not in the package.json file of an embedded package. I believe this is something they are working on, but don't hold your breath. The general workaround is to install the dependencies first, then the package that relies on them next.
So every time I edit, I will edit in another project and push it. Is there a way to edit in an existing project and push it to git?
There is, but it requires a good understanding of git. There is a command that is distributed with many versions of git called git subtree. This lets you have multiple repositories in one project.
Wait, is there a way to put it on git to have multiple people using it on a private repo?
Sure, you can invite anyone to collaborate on a private repo on GitHub - this will ensure they have access. In the specific repository, go into Settings > Collaborators.
Thanks for the bump!
the discord server invitation link is invalid :(
It is working, please try it again in a bit. Check that you haven't joined the max number of allowed Discords!
Be careful putting a Resources folder inside your packages. When someone imports your package, all the files inside the Resources folder in your package will also be part of the project's build regardless if it is being used or not. Spent hours figuring this out trying to hit a 150MB build size limit.
Wow, I’ve never seen that! Great tip!
While custom packages look like a good feature, it's truly a pain to work with in larger projects if you need to change or update the packages to implement a new feature in your game project. It takes a lot of back and forth, swapping out from registry to embedded packages so you can try the features out, then backport it to the package, revert all changes locally, and lastly update the package. Truly awful workflow for the actual game developer that need to build or update the packages to work with their game.
And if you think it will be perfect package on first try without having to change or update it, you are indeed wrong most of the time.
I made a comment of my own regarding this issue before realizing someone else already wrote one. This is the only reason I tend to avoid using packages.