C
C#2y ago
Zenternion

❔ UNITY When I manually execute 2 functions it works but not when executing them from 1 function.

When I run Initialize() it only works the 2ND TIME (First time only runs DestroyCities(), Second time runs both()). But If I do DestroyCities() and then GenerateCities() manually it works EVERY TIME.
public void Initialize()
{
DestroyCities();
GenerateCities();
}

public void GenerateCities()
{
Cities cities = new Cities();
cities = cities.CreateJSON();

int i = 0;

foreach (feature cityData in cities.features)
{.......

public void DestroyCities()
{
for (int
i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go)); //destroys thing (WORKS)
}
}
public void Initialize()
{
DestroyCities();
GenerateCities();
}

public void GenerateCities()
{
Cities cities = new Cities();
cities = cities.CreateJSON();

int i = 0;

foreach (feature cityData in cities.features)
{.......

public void DestroyCities()
{
for (int
i = 0; i < transform.childCount; i++)
{
GameObject go = transform.GetChild(i).gameObject;
StartCoroutine(DestroyFastly(go)); //destroys thing (WORKS)
}
}
Editor:
public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
cityGeneration.Initialize();
}
}

if (GUILayout.Button("Initialize Cities"))
{
cityGeneration.Initialize();
}

if (GUILayout.Button("Generate Cities"))
{
cityGeneration.GenerateCities();
}

if (GUILayout.Button("Destroy Cities"))
{
cityGeneration.DestroyCities();
}

DrawSettingsEditor(cityGeneration.shapeSettings, cityGeneration.OnShapeSettingsUpdated, ref cityGeneration.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(cityGeneration.citySettings , cityGeneration.OnCitySettingsUpdated , ref cityGeneration.citySettingsFoldout , ref cityEditor);
}
public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
cityGeneration.Initialize();
}
}

if (GUILayout.Button("Initialize Cities"))
{
cityGeneration.Initialize();
}

if (GUILayout.Button("Generate Cities"))
{
cityGeneration.GenerateCities();
}

if (GUILayout.Button("Destroy Cities"))
{
cityGeneration.DestroyCities();
}

DrawSettingsEditor(cityGeneration.shapeSettings, cityGeneration.OnShapeSettingsUpdated, ref cityGeneration.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(cityGeneration.citySettings , cityGeneration.OnCitySettingsUpdated , ref cityGeneration.citySettingsFoldout , ref cityEditor);
}
12 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Zenternion
ZenternionOP2y ago
In initialize?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Zenternion
ZenternionOP2y ago
The name 'thread' does not exist in the current context
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Zenternion
ZenternionOP2y ago
oh unity I forgot because unity doesent add using system Same problem @Duke ???
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Zenternion
ZenternionOP2y ago
HOLY SHEESH IT WAS BECAUSE OF yield return new WaitForSeconds(0); @Duke
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2y ago
Sorry @Zenternion your message contained blocked content and has been removed!
Zenternion
ZenternionOP2y ago
unity sometimes is just stupid
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server