Full context:
Im writing a mod that adds a trigger that can save/load a player's position at a certain time. Upon loading the state, the mod invokes VivHelper.PerfectTeleport using Reflection like so:
MethodInfo tele = teleportFunctions.GetMethod("PerfectTeleport", BindingFlags.NonPublic | BindingFlags.Static);
tele.Invoke(null, new object[] {
entityList[i], // the player (this also works with other entites so this is only called if entityList[i] is a Player entity.)
RoomStateTrigger.currScene, // The current scene.
roomName, // The room that the state was saved in.
positionList[i],
true, // endCutscene
false, // actAsTransition
null,
null,
null,
null
});
teleportFunctions is initialized like this:
static EverestModuleMetadata vivHelper = new() {
Name = "VivHelper",
Version = new Version(1, 13 ,3)
};
// ...
if (Everest.Loader.TryGetDependency(vivHelper, out EverestModule vivModule)) {
vivAssembly = vivModule.GetType().Assembly;
teleportFunctions = vivAssembly.GetType("VivHelper.Module__Extensions__Etc.TeleporterFunctions");
}
Within the actual map, states are saved in a given room, and the loading is handled using a Frost Helper Activator setup in a bits&bolts globally loaded room.
- A "recall" flag is controlled by a globally loaded SetFlagOnButtonPressController
- Upon the flag being set to true, a Frost Helper Activator activates my state loading trigger that will grab the Player entity and run the code above to teleport the player.
However, when the player is teleported, the game crashes with aSystem.InvalidOperationException: Collection was modified; enumeration operation may not execute.