Initialising MM with a chosen seed at runtime
As suggested on the forum, I currently start my scene with the MapMagic component disabled. From my scene manager script, I then set the world seed and enable the component as follows:
mapMagic.seed = // seed loaded from savegame file;
mapMagic.enabled = true;
This works in v1.7. However, in the latest Master branch, this is leading to the following errors on entering playmode (only on every other time):
Thread Error: System.ArgumentException: An element with the same key already exists in the dictionary.
at System.Collections.Generic.Dictionary2[System.Type,MapMagic.Action
5[Plugins.CoordRect,MapMagic.Chunk+Results,MapMagic.GeneratorsAsset,MapMagic.Chunk+Size,Plugins.ThreadWorker]].Add (System.Type key, MapMagic.Action`5 value) [0x0007e] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404
at MapMagic.GeneratorsAsset.Generate (CoordRect rect, MapMagic.Results results, Size terrainSize, Int32 seed, Plugins.ThreadWorker worker) [0x001fa] in C:\Users\alast\Projects\Unity\NOME\Assets\MapMagic\Main\GeneratorsAsset.cs:219
at MapMagic.Chunk.ThreadFn () [0x0004f] in C:\Users\alast\Projects\Unity\NOME\Assets\MapMagic\Main\Chunk.cs:189
at Plugins.ThreadWorker.ThreadFn () [0x00020] in C:\Users\alast\Projects\Unity\NOME\Assets\MapMagic\PluginTools\ThreadWorker.cs:501
UnityEngine.Debug:LogError(Object)
Plugins.ThreadWorker:ThreadFn() (at Assets/MapMagic/PluginTools/ThreadWorker.cs:525)
and then (presumably because the chunk is not generated):
ArgumentException: Trying to access out-of-bounds terrain height information. Plugins.WeldTerrains.WeldToPrevZ (System.Single[,]& heights, UnityEngine.Terrain neig, Int32 margin) (at Assets/MapMagic/PluginTools/WeldTerrains.cs:55) MapMagic.HeightOutput+<Apply>c__Iterator2.MoveNext () (at Assets/MapMagic/Generators/OutputGenerators.cs:241) MapMagic.GeneratorsAsset+<Apply>c__Iterator2.MoveNext () (at Assets/MapMagic/Main/GeneratorsAsset.cs:279) MapMagic.Chunk+<ApplyRoutine>c__Iterator0.MoveNext () (at Assets/MapMagic/Main/Chunk.cs:199) Plugins.ThreadWorker.CoroutineFn () (at Assets/MapMagic/PluginTools/ThreadWorker.cs:572) Plugins.ThreadWorker.UpdateApply () (at Assets/MapMagic/PluginTools/ThreadWorker.cs:164) Plugins.ThreadWorker.Refresh () (at Assets/MapMagic/PluginTools/ThreadWorker.cs:137) MapMagic.MapMagic.Update () (at Assets/MapMagic/MapMagic.cs:264)
I see there is now a "Change seed on playmode start" checkbox, but that just seems to randomise the seed - how should I now set a specific seed at scene start in runtime through script?
Comments (5)
-
reporter -
repo owner Seems that I've broken something, will take a look
-
repo owner Does this error still exists?
I could not reproduce it neither with a "Change seed on playmode start" nor with this script:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MMSeedTest : MonoBehaviour { public MapMagic.MapMagic mapMagic; void Start () { mapMagic.seed = 1; // seed loaded from savegame file; mapMagic.enabled = true; } }
-
reporter I just downloaded the latest Master branch and I'm no longer getting the error as before. However, the behaviour still doesn't quite seem correct...
This is most obviously demonstrated by the following steps:
- Setting a seed in the inspector (say, 12345)
- Pinning a terrain chunk (but not locking it)
- Disabling the MM component
- Attach the MMSeedTest script you posted earlier to an object in the scene
- Enter Playmode
Although the seed of the MapMagic object will change from 12345 to 1, as shown in the inspector panel, the pinned terrain chunk will remain the same as it was, even though it was created under a different seed.
I thought pinned terrain chunks were always regenerated at runtime, or do I need to add an explicit Generate() to that script?
-
repo owner Well, I can see what confuses here. You are right, pinned terrain should be re-generated, while locked one should remain untouched.
- Log in to comment
I've just noticed that I also intermittently get these errors when enabling the "Change Seed on Playmode Start" option on a vanilla installation of MM.