- Home /
getter and setter not working
Hey Guys having a problem getting my get/set to work and not sure why cause I've had working before.
Item is a scriptable object and the script is attached to a UI component if that has anything to do with it None of the debugs are showing up in console either.
public class ItemSlot : MonoBehaviour
{
[SerializeField] public Item m_slotItem;
[SerializeField] private Image slotIcon;
[SerializeField] [ExecuteInEditMode] public Item SlotItem
{
get
{
Debug.Log("1");
return m_slotItem;
}
set
{
m_slotItem = value;
Debug.Log("2");
if(m_slotItem == null)
{
slotIcon = InvUIManager.singleton.EmptyIcon;
return;
}
slotIcon.sprite = m_slotItem.invIcon;
}
}
}
Would appreciate any information or any links to anything I might have missed
Answer by SlowCircuit · Jun 18, 2018 at 08:51 PM
You can not set one specific variable to execute in edit mode. You have to set the whole class to it. So remove [ExecuteInEditMode] and place it above the class declaration. Then the entire script will run in edit mode. If you don't want the entire script to run in edit mode, then you need to rework how you've set this up.
Your answer
Follow this Question
Related Questions
Abstract Inheritance and abstract variables sloppy code 1 Answer
C# generics and getters/setters with Unity iPhone 1 Answer
Javascript : Get variable & run a method from another script 0 Answers
Proper use of c# properties? 1 Answer
Make a public variable with a private setter appear in inspector 3 Answers