Thanks a lot for this one. Really simple but so powerful. I also find it very useful if the value changes can be ‘observed’ optionally, don’t know what’s the best way, but I ended up manually doing a ‘ValueChanged’ event on them so that in the code that uses the ValueRefs, they can subscribe to events like “ColorRef.Changed += ChangeGraphicColorMethod”, subscribe-unsubscribe onEnable/OnDisable pairs (maybe not the best place for this). The idea is to use simple methods to react to changes instead of plaguing Update cycles with more crowded logic. Still can have a purpose for really complex logic, but the lift up could happen on the events first. Maybe something more clever can be done? Like an “ObservableReference” separate class or maybe built-in on the value reference base class... don’t know.
Awesome video, so useful. I learned a lot about C#/Odin programming working through this. I will note that the Tutorial Files link is incorrect, the link goes to 'Struct Value Drawers' instead of Value Reference Toggling (which unfortunately I cannot find).
Sorry about that. Looks like we didn't push all the files but you can find the Color Reference value scripts here:github.com/onewheelstudio/DevdogTutorialFiles/tree/c6e5c29956f0de20ba907c62ffb08707a5cfa1f9/ScriptableObjects/Color%20SOs
Really cool solution, but I have an issue. How do I apply Odin attributes to the different derived ValueAssets? For example, if I have a PercentileAsset where the value is a simple float. How do I give it a PropertyRange attribute from 0 to 1? Where should that attribute be placed?
Here's a response from the developers (I'm just the YT guy). It might be worth dropping by the Odin discord (link in any description) to get more detailed help. That's kinda tricky. It might be possible to make some kind of attribute processor that grabs attributes from the parent ValueAsset object, and moves them to the actual value property inside the class.
This is awesome. BTW is there a way to have the dropdown only display the icon until you click on it? Basically like if I did the editor via script and used the ImagePosition.ImageOnly property in a defined GUI style.
I ended up using a simple button to toggle on and off the useValue field. I used the following code for a nice and clean result : protected bool useValue = true; [HorizontalGroup("Reference", 30)] [Button(SdfIconType.ArrowLeftRight, Name = "")] protected void Switch() { useValue = !useValue; }
It still not quite clear to me the need for the double reference... I think it was about having the ability edit it there directly but making the intention obvious? If you do what you mean with a ‘ShowInspector, InlineEditor’ and other attributes, I think it would display all the editing features and be editable right?
@@alejmc The first field is there to have a regular field for a scriptable object to put in. The second field is there to render the inline editor instead of the field for the scriptable object.
Mainly useful for larger teams or more design oriented devs as this gives a lot of control from the editor. If you want the full benefits watch the talk he mentions, where Ryan Hipple actually explains how it is used in a succesful gamedev studio. Additionally, its a pretty alright alternative for singletons.
Hi there, great tutorial, very helpful! Quick question: the implicit operator doesn't seem to work for me. It allows me to return the valueRef._value (from the ValueReference script), but not the valueRef.value (from the ValueAsset script). What am I doing wrong? This doesn't work: public static implicit operator TValue(ValueReference valueRef) { return valueRef.value; }
This operator will only work on the type "ValueReference" if you want a similar operator for another type you can create a similar operator for that type.
If you scroll about halfway down on the link below, you there are a bunch of written tutorials on the Odin Serializer. Link: odininspector.com/tutorials Otherwise, jump on the Odin Discord and ping Tor or Mikkel. They should be able to answer any questions on the serializer.
The one asset I'd recommend regardless of project type. From prototype to production and regardless of genre. Supremely useful.
Amazing!!!
Thanks a lot for this one. Really simple but so powerful.
I also find it very useful if the value changes can be ‘observed’ optionally, don’t know what’s the best way, but I ended up manually doing a ‘ValueChanged’ event on them so that in the code that uses the ValueRefs, they can subscribe to events like “ColorRef.Changed += ChangeGraphicColorMethod”, subscribe-unsubscribe onEnable/OnDisable pairs (maybe not the best place for this).
The idea is to use simple methods to react to changes instead of plaguing Update cycles with more crowded logic. Still can have a purpose for really complex logic, but the lift up could happen on the events first.
Maybe something more clever can be done? Like an “ObservableReference” separate class or maybe built-in on the value reference base class... don’t know.
how an earth is it simple?
Awesome video, so useful. I learned a lot about C#/Odin programming working through this. I will note that the Tutorial Files link is incorrect, the link goes to 'Struct Value Drawers' instead of Value Reference Toggling (which unfortunately I cannot find).
Sorry about that. Looks like we didn't push all the files but you can find the Color Reference value scripts here:github.com/onewheelstudio/DevdogTutorialFiles/tree/c6e5c29956f0de20ba907c62ffb08707a5cfa1f9/ScriptableObjects/Color%20SOs
Really cool solution, but I have an issue.
How do I apply Odin attributes to the different derived ValueAssets?
For example, if I have a PercentileAsset where the value is a simple float. How do I give it a PropertyRange attribute from 0 to 1?
Where should that attribute be placed?
Here's a response from the developers (I'm just the YT guy). It might be worth dropping by the Odin discord (link in any description) to get more detailed help.
That's kinda tricky. It might be possible to make some kind of attribute processor that grabs attributes from the parent ValueAsset object, and moves them to the actual value property inside the class.
This is awesome. BTW is there a way to have the dropdown only display the icon until you click on it? Basically like if I did the editor via script and used the ImagePosition.ImageOnly property in a defined GUI style.
If you find a way to do this share it with me, I'm quite interested.
I ended up using a simple button to toggle on and off the useValue field. I used the following code for a nice and clean result :
protected bool useValue = true;
[HorizontalGroup("Reference", 30)]
[Button(SdfIconType.ArrowLeftRight, Name = "")]
protected void Switch()
{
useValue = !useValue;
}
Cool
Instead of having a second field _assetReference, why not just use a property?
protected TAsset AssetReference => assetReference;
It still not quite clear to me the need for the double reference... I think it was about having the ability edit it there directly but making the intention obvious? If you do what you mean with a ‘ShowInspector, InlineEditor’ and other attributes, I think it would display all the editing features and be editable right?
I didn't understand it either. I just hid it from the UI
@@alejmc The first field is there to have a regular field for a scriptable object to put in. The second field is there to render the inline editor instead of the field for the scriptable object.
Pretty sure that the issue there is that unity can't serialize a custom property, it can only handle an autoproperty
would be nice if there are more use case to justify the work needed to make this...
Mainly useful for larger teams or more design oriented devs as this gives a lot of control from the editor. If you want the full benefits watch the talk he mentions, where Ryan Hipple actually explains how it is used in a succesful gamedev studio.
Additionally, its a pretty alright alternative for singletons.
Hi there, great tutorial, very helpful! Quick question: the implicit operator doesn't seem to work for me. It allows me to return the valueRef._value (from the ValueReference script), but not the valueRef.value (from the ValueAsset script). What am I doing wrong? This doesn't work:
public static implicit operator TValue(ValueReference valueRef)
{
return valueRef.value;
}
This operator will only work on the type "ValueReference" if you want a similar operator for another type you can create a similar operator for that type.
With this asset it's possible to "keep/save" a list or an array of System . Object[] in the Editor?
Yes, with Odin serialization you can do that.
@@sirenix7891 is there a tutorial or guide to do that specifically?
If you scroll about halfway down on the link below, you there are a bunch of written tutorials on the Odin Serializer. Link: odininspector.com/tutorials
Otherwise, jump on the Odin Discord and ping Tor or Mikkel. They should be able to answer any questions on the serializer.
fckn complicated