Accessing Project Dependencies
In Unity projects, managing dependencies is crucial for maintaining a clean and efficient workflow. Here, we will discuss two common types of dependencies: Unity package references using Git HTTPS and Git submodules.
Unity Package References Using Git HTTPS
Unity allows you to reference packages directly from a Git repository using HTTPS.
manifest.json
Example Git HTTP Reference in {
"dependencies": {
"com.mycompany.mypackage": "https://github.example.com/myuser/myrepository.git"
}
}
This works fine if the repository is public, but if it is private, you will need to generate a private access token to access the repository.
How to access a private Git HTTPS dependency
- Allow Private Access Tokens: If the dependency is owned by a GitHub organization, ensure that the dependency’s organization allows the use of private access tokens. Go to the organization’s settings and look under
Third-party access > Private access tokens
. - Generate a Private Access Token: In your user settings, navigate to
Developer settings > Private access tokens
and create a private access token in GitHub withrepo
read access to the dependencies. - Add the Token as a Secret: Add the generated token as a secret to the Unity project’s repository or organization. Go to
Settings > Secrets and variables > Actions
. - Include the Token in Actions/Checkout: Modify your Buildalon workflow to include the token in the
actions/checkout
step:
uses: actions/checkout@v4
with:
token: ${{ secrets.CI_TOKEN }}
Unity Package Refrences Using Git SSH
Unity allows you to reference packages directly from a Git repository using SSH. This method is useful for including external libraries or shared codebases.
manifest.json
Example Git SSH Reference in {
"dependencies": {
"com.mycompany.mypackage": "ssh://git@mycompany.github.com/gitproject/com.mycompany.mypackage.git"
}
}
How to access a private Git SSH dependency
- Generate an SSH Key: Generate an SSH key pair on your local machine using
ssh-keygen
and add the public key to your Git repository. - Add the Private Key as a Secret: Add the private key as a secret to the Unity project’s repository or organization. Go to
Settings > Secrets and variables > Actions
. - Include the Key in Actions/Checkout: Modify your Buildalon workflow to include the private key in the
actions/checkout
step:
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
Git Submodules
Git submodules allow you to include and track external repositories within your main repository.
This works fine if the repository is public, but if it is private, you will need to generate a private access token to access the repository. These are the same steps as above using either a private access token or SSH key. Additionally, add the submodules: 'recursive'
option to the actions/checkout
step:
uses: actions/checkout@v4
with:
token: ${{ secrets.CI_TOKEN }}
submodules: 'recursive'
Unity Package Reference using a private scoped registry
Unity allows you to reference packages from a private scoped registry. This method is useful for including internal libraries or shared codebases.
You can access a private scoped registry using the upm-config action.
Next Steps
- Triggers: Set up triggers to start workflows automatically.
- Build Unity: Set up automated builds for your Unity project.
- Buildalon Actions: Explore the actions available to use in your workflows.
- Unit Testing: Automate unit testing to ensure stability and quality.
- Deploy to Stores: Add deployment steps to distribute your app to users.
- Dependencies: Learn what to do if your project depends on other private packages or repositories.