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

Editor: support loading a game with invalid property values #2563

Open
ivan-mogilko opened this issue Nov 1, 2024 · 2 comments
Open

Editor: support loading a game with invalid property values #2563

ivan-mogilko opened this issue Nov 1, 2024 · 2 comments
Labels
context: editor assets related to input files for editing the game type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor

Comments

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Nov 1, 2024

There's a certain problem, which is not too likely, but still potentially possible.
Our serialization system in the Editor works by reading xml entries, and assigning their values to game object properties in memory.
Some of the object properties throw exceptions if the value is not valid.
That works well for reporting when user edits these values in the editor; because value reverts to a previous one, user sees the error message, and can fix it or leave previous value.
But that does not work when a game is loaded, because there's no "fallback" operation. This results in game unable to load at all, and the only way to fix it is to open Game.agf by hand and edit it. That is very inconvenient, not to mention that user has to know valid range of values for this property.

We need some kind of backup scenario in case game cannot load like that.
I suppose, that for this scenario:

  1. We need a distinct exception class thrown by properties when they are assigned an invalid value. ArgumentException may not be a suitable choice, as it's too generic and may be thrown by a multitude of .NET functions. It's better to create a new custom one instead (may derive from ArgumentException), and make sure that properties throw only that.
  2. We need to handle such situation to be able to proceed. From what I see there are 2 main options:
    A. Leave property unchanged (it will likely retain default value), or assign default value explicitly (can use reflection).
    B. Find a closest value in valid range (?), but not sure if that's meaningful, and not every property type can have that.
  3. We need to record this problem, and report to user after game was loaded, in Output panel, and maybe somewhere else, like write a log file into the project folder.
@ivan-mogilko ivan-mogilko added type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor context: editor assets related to input files for editing the game labels Nov 1, 2024
@ericoporto
Copy link
Member

Is this something that is mainly for the enum values or does this affects all properties?

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Nov 2, 2024

Is this something that is mainly for the enum values or does this affects all properties?

Any property that has a valid range. I do not have full list of them right now. For example:

  • script name, which cannot have other symbols but ASCII letters and digits and underscore
  • filepaths (like in Sprite, or AudioClip), which cannot have forbidden symbols
  • integer values that must be > 0 in certain properties
  • tint values afaik have a range of 0-100

The enum properties in particular may cause exception at a step where C# parses a read string into a type (enum value) and fails. But in this issue I'm addressing also properties where the string->type conversion was successful, but it's setting the property which failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context: editor assets related to input files for editing the game type: enhancement a suggestion or necessity to have something improved what: editor related to the game editor
Projects
None yet
Development

No branches or pull requests

2 participants