Skip to content

Commit c920377

Browse files
committed
Fix coroutine state machine attribute.
1 parent 819831f commit c920377

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Murder/Core/Engine/MonoWorld.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ private Entity FetchNextFreeEffectEntity(out Coroutine coroutine)
207207
}
208208
}
209209

210-
Entity e = AddEntity();
210+
Entity e = AddEntity(
211+
new DoNotPersistEntityOnSaveComponent());
212+
211213
_effectEntities.Add(e.EntityId);
212214
coroutine = new(_nextFreeEffectEntityIndex);
213215

src/Murder/Services/CoroutineServices.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ public static Entity RunCoroutine(this Entity e, IEnumerator<Wait> routine)
3535
return e;
3636
}
3737

38-
public static void FireAfter(this World world, float seconds, Action action)
38+
public static Coroutine FireAfter(this World world, float seconds, Action action)
3939
{
40-
Entity e = world.AddEntity();
41-
e.RunCoroutine(WaitAndRun(seconds, action));
40+
if (world is not MonoWorld murderWorld)
41+
{
42+
GameLogger.Warning("Unable to run coroutine on a world that is not MonoWorld.");
43+
return new();
44+
}
45+
46+
return murderWorld.RunCoroutine(WaitAndRun(seconds, action));
4247
}
4348

4449
private static IEnumerator<Wait> WaitAndRun(float seconds, Action action)
4550
{
4651
yield return Wait.ForSeconds(seconds);
47-
4852
action.Invoke();
4953
}
5054
}

src/Murder/StateMachines/CoroutineStateMachine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Murder.StateMachines;
88
/// This CANNOT and WONT be serialized it is just a bad idea. Remember, we can't (or don't want to) serialize lambdas.
99
/// </summary>
1010
[RuntimeOnly]
11-
[DoNotPersistEntityOnSave]
1211
public class CoroutineStateMachine : StateMachine
1312
{
1413
private readonly IEnumerator<Wait> _routine;

0 commit comments

Comments
 (0)