Skip to content

Conversation

@mbedda
Copy link
Contributor

@mbedda mbedda commented Jan 30, 2026

Setting 0 was getting omitted

Credit: Evora

@evs-ptr
Copy link

evs-ptr commented Jan 30, 2026

It was discussed in the discord channel. The reason for this PR is to allow developers to actually set VerticalNormalizedPosition and HorizontalNormalizedPosition to 0 value.

It didn't work before because JSON serializer omitted 0 value cause of default value handling. But setting DefaultValue attribute to -1 and actual value -1 by default will allow developers to explicitly set whatever value they want between 0 and 1.

-1 is invalid, according to unity, at any case for those two, so should be safe to use it as default value marker. If set to -1 JSON serializer will ignore this property now.

https://github.com/Facepunch/Rust.Community/blob/f1eef905473105e7814b984bc5745d4d9cbaa006/CommunityEntity.UI.cs#L809
https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.ScrollRect-horizontalNormalizedPosition.html
https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.ScrollRect-verticalNormalizedPosition.html

src/RustCui.cs Outdated
Comment on lines 870 to 875
[DefaultValue(-1f)]
public float HorizontalNormalizedPosition { get; set; } = -1f;

[JsonProperty("verticalNormalizedPosition")]
public float VerticalNormalizedPosition { get; set; }
[DefaultValue(-1f)]
public float VerticalNormalizedPosition { get; set; } = -1f;
Copy link
Member

Choose a reason for hiding this comment

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

Hi, I might be missing something but is there a reason we are not looking to do something like this instead?

Suggested change
[DefaultValue(-1f)]
public float HorizontalNormalizedPosition { get; set; } = -1f;
[JsonProperty("verticalNormalizedPosition")]
public float VerticalNormalizedPosition { get; set; }
[DefaultValue(-1f)]
public float VerticalNormalizedPosition { get; set; } = -1f;
public float? HorizontalNormalizedPosition { get; set; }
[JsonProperty("verticalNormalizedPosition")]
public float? VerticalNormalizedPosition { get; set; }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would work fine too. 👍

Copy link

Choose a reason for hiding this comment

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

Will work too.

Copy link

Choose a reason for hiding this comment

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

It was made like this only to avoid nullability of value types. But both approaches are valid.

Copy link

Choose a reason for hiding this comment

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

Nullable value types use more memory compared to just value type. Because it is being wrapped into Nullable struct. I don't have benchmarks, nor does it matter a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah if you want me to commit your suggestion for easier merge I don't mind (or if you wanna do it manually), it would work fine both ways only difference is that they won't be able to set -1f with the original commit which can only be used to do some animation so exact value doesn't matter.

Value 0 was default and therefore omitted
@ads102003 ads102003 merged commit 87e28ea into OxideMod:develop Jan 31, 2026
@ads102003
Copy link
Member

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants