Toggle to make optional Scene parameters required (Strict Mode?)

TLDR:

  • Adding a second scene causes unpredictable behavior in a large project where the code has many objects created with unspecified optional scene parameters
  • Adding a flag to make scene parameters required would allow easier location of where I forgot to specify them

I have a fairly large project a little over 2 years old. Recently I added a second Scene and found that doing so caused several errors in observed behavior, but no errors in the console. I eventually realized this was because of not passing explicit scene parameters to several constructors spread across the codebase and the timing of my instantiation of the second scene causing some to be created in my first “main” scene and others created later being placed in the “secondary” scene due to the behavior that constructors use the most recently created scene if none is passed.

Now I need to sift through a lot of code and find every place that I didn’t provide a scene parameter in every constructor type where it is optional. It would be nice if I could turn on a compiler flag to change the scene parameters to be required then I could just go to the line in the error and fix them. As it is I’ll have to hunt down manually using grep and will likely miss some places.

idk if it’s possible for users to enable testing that. cc @RaananW

let me simplify this - you want Babylon to tell you when you forgot to provide a required parameter and make optional parameters required so that they will be caught here as well?

Not exactly. I don’t need most optional parameters to be required, but specifically scene because of the behavior that it defaults to using LastCreatedScene. As far as required parameters I think they are already caught by the TS compiler if forgotten, but maybe I’m misinterpreting what you meant by forgetting a required parameter.

Maybe it would be possible to make a lint rule about it, but I’m not experienced in creating linter rules and I’m not sure if that would even be the easiest way to do it. Another approach that someone used was “banning” LastCreatedScene: Ban LastCreatedScene but I’m worried that other things I don’t know about may depend on that.

got you.
we can see how easy it is to add an optional “Ban LastCreatedScene”. i don’t think it’s a big issue and I believe (without 100% checking TBH) that we don’t use it directly in the code. just as a fallback.

1 Like