Can Unity Needle builds access the Unity ProjectSettings values (like Product Name or Version)?

In particular, we’ve been relying on Unity’s “Application.version” to show our internal staff what build they’re playing, and are curious if we’ll be able to continue doing so, or if we’ll need to develop some new way to version our builds. Is Needle exporting that data anywhere into its builds?

Original Post on Discord

by user 248501710404845568

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

SJkl, in Needle Engine, version information can be included within the package.json of your web project. Similar to a Node.js project, you can define a version number in the package.json which can be used by your internal staff to identify the build they’re playing. Here is an example where the version is set:

"version": "1.0.0"

This version number is specified in your project’s package.json file. You can update this value for new builds to keep track of different versions (see the documentation).

1 messages left GPT 4
Thanks for your feedback!

that’s cool, but is it possible to access that value from within the build, at runtime? (EDIT: without additional dependencies?)

by user 248501710404845568

and also, that doesn’t quite answer the original question of whether or not any of the Unity ProjectSettings values are exported… seems like the answer is “no”?

by user 248501710404845568

hmm… it looks like import { version } from '../../package.json'; works well enough for dev builds, but I imagine it’s not the best idea to just keep that around on Production webservers

by user 248501710404845568

One quick way to include this info would be by making a component with a public property getter that just returns the version number. Make sure to have a matching typescript component of course.

You could ensure this component is present in any scene by adding it automatically through the Needle Engine Core Builder static events (using BuildStarted for example)

Let me know if that would be sufficient already.
You could achieve the same thing without a component by using a vite plugin and defines but it involves a bit more extra work that might not be necessary

// @dont-generate-component
export class ProjectVersion extends Behaviour {

    version!: string;
public class ProjectVersion : MonoBehaviour
    public string Version => Application.version;

very clever!! this is sufficient, thanks so much for the technique and the example!

by user 248501710404845568