Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom package settings #5027

Merged
merged 25 commits into from
Mar 18, 2021
Merged

Add custom package settings #5027

merged 25 commits into from
Mar 18, 2021

Conversation

dongruoping
Copy link
Contributor

@dongruoping dongruoping commented Mar 3, 2021

Proposed change(s)

Add customizable ML-Agents settings in project settings.
Users can create asset for their own projects.

Settings are accessible in editor and player build.
Multiple settings assets are allowed (displayed in drop-down list).

Currently only contains Connect to Trainer and Editor Training Port. More can be added later.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@dongruoping dongruoping marked this pull request as ready for review March 12, 2021 01:06
@dongruoping dongruoping changed the title Add custom project settings Add custom package settings Mar 12, 2021
@@ -0,0 +1,74 @@
using System.Linq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a dumb question, but why do we have a BuildSettingsProvider if none of the settings are used in a build? (They are all Editor only settings?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are used in builds, if you don't want to train or even try to connect to a trainer in a game that's being shipped you'd want to know that in your build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used in builds. If you don't want to train or even try to connect to a trainer in a game that's being shipped, you'd want to know that in your build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the use case it to remove the command line argument listeners on the build? Because a build will not try to listen to a trainer unless a specific command line argument is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Originally I made a player training port but that doesn't seem to make much sense so I removed that.
But I still think there's chance that we'll add settings that is used in player (analytics? academy stepping?)

private static void ClearPlayerSettingsDirtyFlag()
{
#if UNITY_2019_OR_NEWER
var settings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlayerSettings? I thought this would be an MLAgentsSettings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're injecting our settings into the preload assets in PlayerSettings and these method is to detect/clear the dirty flag of PlayerSettings before/after we put in our settings. So PlayerSettings here is correct.

com.unity.ml-agents/Runtime/MLAgentsManager.cs Outdated Show resolved Hide resolved
#else
internal static void InitializeInPlayer()
{
s_Settings = Resources.FindObjectsOfTypeAll<MLAgentsSettings>().FirstOrDefault() ?? ScriptableObject.CreateInstance<MLAgentsSettings>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s_Settings = Resources.FindObjectsOfTypeAll<MLAgentsSettings>().FirstOrDefault() ?? ScriptableObject.CreateInstance<MLAgentsSettings>();
Settings = Resources.FindObjectsOfTypeAll<MLAgentsSettings>().FirstOrDefault() ?? ScriptableObject.CreateInstance<MLAgentsSettings>();

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. The callback in Settings setter is for refreshing in the editor so should not really matter though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain in comments why we have both Settings and s_Settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments on the getter/setter

class MLAgentsSettings : ScriptableObject
{
[SerializeField]
private bool m_ConnectTrainer = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were other settings that we talked about adding later - should we group/nest these now so that we don't have to go through hoops to move them around in the future?

Copy link
Contributor Author

@dongruoping dongruoping Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can group them into Training Port or Trainer Settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriselion by group/nest these do you mean nesting them in the code (like a subclass in MLAgentsSettings) or just grouping in editor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way - I think using a subclass in MLAgentsSettings makes the grouping in the editor more automatic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we always need to manually layout the fields in MLAgentsSettingsProvider.OnGUI, it's less important. But it might let us just add the "top level" settings (like TrainerSettings) and not have to worry about new fields when we add them.

Copy link
Contributor

@chriselion chriselion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some user-facing documentation on how to enable these, and how to have different settings for training/inference?

@dongruoping dongruoping changed the base branch from main to v2-staging March 16, 2021 22:02
docs/Package-Settings.md Outdated Show resolved Hide resolved
docs/Package-Settings.md Outdated Show resolved Hide resolved
Copy link
Contributor

@surfnerd surfnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good. I'd like to see some Edit mode test coverage on these files. After that we can :shipit:

Copy link
Contributor

@chriselion chriselion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Pending other feedback)

@dongruoping
Copy link
Contributor Author

Tests added. I placed it under DevProject to have a place to create settings asset on the fly during tests.
The reason is that I found it hard to write meaningful tests without actually interact with asset and I can’t use something like MockFileSystem since the asset APIs require things placed under Asset/.
To reserve a place that I can create assets that won't conflict with existing files I put the tests in a separate folder in DevProject.

@dongruoping
Copy link
Contributor Author

dongruoping commented Mar 18, 2021

2018 tests are failing and are expected since I removed the 2019_OR_NEWER flags.
Do we plan to remove them?

@surfnerd surfnerd closed this Mar 18, 2021
@surfnerd surfnerd deleted the branch v2-staging March 18, 2021 21:37
@surfnerd surfnerd reopened this Mar 18, 2021
Copy link
Contributor

@surfnerd surfnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dongruoping dongruoping merged commit 3762dd2 into v2-staging Mar 18, 2021
@delete-merged-branch delete-merged-branch bot deleted the develop-package-settings branch March 18, 2021 22:14
surfnerd pushed a commit that referenced this pull request Mar 18, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants