Answer the question
In order to leave comments, you need to log in
How to keep changing values when switching to PlayMode?
Hello! In general, the situation is as follows: the components have methods available through the ContexMenu. They work as they should. But I decided to automate a little and write a script where these methods are called automatically. And here is where the problem lies. Component values that are set during the execution of these methods are reset when PlayMode is started. How, exactly, to fix this?
Component Methods:
First:
[ContextMenu("Fill spaces")]
public void FillSpaces()
{
connections = new List<Transform>();
LineController[] lines = GameObject.FindObjectsOfType<LineController>();
foreach (var line in lines)
{
string[] knotNames = line.gameObject.name.Split('-');
if (knotNames.Length != 2)
{
LoggerManager.Instance.Error(this, "Incorrect line name. Example: {KnotName1}-{KnotName2}");
}
if (knotNames[0] == gameObject.name)
{
connections.Add(GameObject.Find(knotNames[1]).transform);
}
else if (knotNames[1] == gameObject.name)
{
connections.Add(GameObject.Find(knotNames[0]).transform);
}
}
}
[ContextMenu("Fill spaces")]
public void FillSpaces()
{
List<string> knotNames = new List<string>(gameObject.name.Split('-'));
top = GameObject.Find(knotNames[0]).GetComponent<Knot>();
bottom = GameObject.Find(knotNames[1]).GetComponent<Knot>();
}
[MenuItem("Config/AutoConfigLevel")]
public static void AutoConfigLevel()
{
Knot[] knots = GameObject.FindObjectsOfType<Knot>();
foreach (var knot in knots)
{
knot.FillSpaces();
}
LineController[] lines = GameObject.FindObjectsOfType<LineController>();
foreach (var line in lines)
{
line.FillSpaces();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question