[Resolved]Using Set functions for properties in custom editor scripts.

Hey,

I thought I had a cool idea, but it failed. It ends up freezing unity and giving me an error.

StackOverflowException: The requested operation caused a stack overflow.
GameCreator.CustomModules.RTS.SelectableObjectManager.get_DragBoxBorderColour () (at Assets/Plugins/GameCreatorModules/RTS/Scripts/SelectableObjectManager.cs:19)
.........
GameCreator.CustomModule.R<message truncated>

So in my class I have something like this… The set calls a function.

public Color DragBoxBorderColour
{
    get => DragBoxBorderColour;
    get => DragBoxBorderColour = SetDragBoxColour(DefaulDragBoxColourTypeEnum.Border, value);
}

And in the editor class I have this

_Target.DragBoxBorderColour = EditorGUILayout.ColorField(GUIC_DragBoxBorderColour, _Target.DragBoxBorderColour);

Fails Hard!!! I tested that the function used inside the set, on a Button function from the inspector and it works fine. It just doesn’t like my setup.

Is there a way to fix this or am I violating some kind of principal?

Thanks in advance :wink:

Though it has not fixed my problem, I just realized I setup my variable wrong in case anyone thought the return was the issue.

It’s now…

public Color DragBoxBorderColour
{
    get { return DragBoxBorderColour; }
    get => DragBoxBorderColour = SetDragBoxColour(DefaulDragBoxColourTypeEnum.Border, value);
}

Resolved!!!

I had to modify a private property.

Like so…

private Color dragBoxBorderColour = new Color(0, 0.7f, 1, 0.6f);
public Color DragBoxBorderColour
{
    get { return dragBoxBorderColour; }
    set => dragBoxBorderColour = SetDragBoxColour(DefaulDragBoxColourTypeEnum.Border, value);
}