- Home /
How can I set the properties of serialised fields on an object recusively?
Basically I have this:
[Serializable]
public class BaseSpell : MonoBehaviour, ISpell
{
[SerializeField]
public Texture2D Icon;
[SerializeField]
public BaseTargetting SpellTargetting;
[SerializeField]
public BaseType SpellType;
[SerializeField]
public List<BaseEffect> SpellEffect;
}
And base targetting is then set to the following: (note: BaseTargetting inherits from MonoBehaviour)
[Serializable]
class TargettingLine : BaseTargetting
{
[SerializeField]
public Texture2D LineTexture;
public override void OnSelect(Unit player)
{
Debug.Log("OnSelect: TargettingLine");
}
}
When I create an object with BaseSpell attached I can then assign it's properties to prefabs with these other classes attached.
However, I cannot then assign the LineTexture property of the TargettingLine class. How would I gain access to this?
My issue from there would be how I would achieve the same goal with the list (public List SpellEffect;)
One thing I want to avoid is having to add custom code to every object to display these properties in the GUI. For example, I would want to avoid adding a custom GUI to the TargettingLine class, as I plan on having a large variety of target types and want to avoid re-writing the same code repeatedly as much as I can.
Thanks!
(I am however wondering if I might be best simply assigning all properties in a non-monobehaviour way and storing them outside of the game world. The downside of this is just that I can make spells within the editor)
Your answer
![](https://koobas.hobune.stream/wayback/20220612150020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
A node in a childnode? 1 Answer
Get variable from Script in list and , set direct link to other script 1 Answer
Adding scripts to items in a list 1 Answer