-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Don't inherit from Academy, remove virtual methods #3184
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
Conversation
|
||
// Override | ||
Physics.gravity *= gravityMultiplier; | ||
Time.fixedDeltaTime = fixedDeltaTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most scenes only care about gravity, but Crawler and Walker override these deltaTime and solver iterations settings.
Physics.defaultSolverIterations = solverIterations; | ||
Physics.defaultSolverVelocityIterations = solverVelocityIterations; | ||
|
||
var academy = FindObjectOfType<Academy>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will eventually be replaced with singleton access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it a lot so far. (Not approving only because it is WIP)
@@ -8,7 +8,7 @@ public override void InitializeAcademy() | |||
Monitor.verticalOffset = 1f; | |||
Physics.defaultSolverIterations = 12; | |||
Physics.defaultSolverVelocityIterations = 12; | |||
Time.fixedDeltaTime = 0.01333f; // (75fps). default is .2 (60fps) | |||
Time.fixedDeltaTime = 0.01333f; // (75fps). default is .02 (60fps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<opinion>
I do think we should avoid changing those in our environments.
</opinion>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the history of them; since the scenes that override them are using ragdolls, I assume it was to improve stability. It might all change with the physx changes anyway.
UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/SettingsOverrides.cs
Outdated
Show resolved
Hide resolved
int m_OriginalSolverIterations; | ||
int m_OriginalSolverVelocityIterations; | ||
|
||
public float gravityMultiplier = 1.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should have gravity multiplier or gravity setting (with default at -9.81)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the scenes today use a multiplier (but FloatPropertiesChannel use the negative of the value)
@@ -0,0 +1,52 @@ | |||
using UnityEngine; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is SimulationSettingsOverrides
more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is directly modifying what unity calls ProjectSettings
, maybe ProjectSettingsOverrides
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works for me too. Since this will only be used in our scenes, I'm less worried about the naming or making sure that it handles all possible cases.
UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/SettingsOverrides.cs
Outdated
Show resolved
Hide resolved
Seems ok to me. |
Assert.AreEqual(0, aca.GetStepCount()); | ||
Assert.AreEqual(0, aca.GetEpisodeCount()); | ||
Assert.AreEqual(0, aca.GetTotalStepCount()); | ||
Assert.AreEqual(null, aca.FloatProperties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions for other things to check before and after initialization?
@@ -39,23 +45,11 @@ namespace MLAgents | |||
/// </remarks> | |||
[HelpURL("https://github.com/Unity-Technologies/ml-agents/blob/master/" + | |||
"docs/Learning-Environment-Design-Academy.md")] | |||
public abstract class Academy : MonoBehaviour | |||
public class Academy : MonoBehaviour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make this sealed
or is that overkill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would clearly communicate that the Academy is not to be subclassed anymore. It makes sense to add sealed
to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, forgot to add this. If for some reason, I don't get the singleton implemented before the next release, I'll seal it for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a no brainer to me
var academy = FindObjectOfType<Academy>(); | ||
academy.LazyInitialization(); | ||
|
||
academy.FloatProperties.RegisterCallback("gravity", f => { Physics.gravity = new Vector3(0, -f, 0); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's no UnRegisterCallback
on FloatProperties
at the moment. This could be an issue when Academy is a singleton and scenes are switched.
So if I have something I need to do every time there is an Academy Step, should I be using Hmm, looking at the old code, |
Make Academy non-abstract, and replace all child classes of it.
Suggested replacements for the Academy virtual methods: