OndrejNepozitek / Edgar-Unity

Unity Procedural Level Generator
https://ondrejnepozitek.github.io/Edgar-Unity/docs/introduction
MIT License
820 stars 70 forks source link

Fog Of War Implementation : Each polygon must have at least 4 points. #114

Closed hugojobe closed 2 years ago

hugojobe commented 2 years ago

Hi ! I followed exactely the tutorial in the documentation but I get this error at runtime :

Can you help me please ?

Thanks :)


Edgar.Geometry.PolygonGrid2D.CheckIntegrity()`
Edgar.Geometry.PolygonGrid2D..ctor (System.Collections.Generic.IEnumerable`1[T] points)
Edgar.Unity.Polygon2D.GetGridPolygon () (at Assets/Edgar/Runtime/Common/Utils/Polygon2D.cs:94)
Edgar.Unity.Polygon2D.GetAllPoints () (at Assets/Edgar/Runtime/Common/Utils/Polygon2D.cs:75)
Edgar.Unity.FogOfWarGrid2D.GetPolygonPoints (Edgar.Unity.Polygon2D polygon) (at Assets/Edgar/Runtime/Grid2D/Common/FogOfWar/FogOfWarGrid2D.cs:555)
Edgar.Unity.FogOfWarGrid2D.GetTilesToReveal (System.Collections.Generic.List`1[T] roomsToReveal) (at Assets/Edgar/Runtime/Grid2D/Common/FogOfWar/FogOfWarGrid2D.cs:289)
Edgar.Unity.FogOfWarGrid2D+<RevealRoomCoroutine>d__50.MoveNext () (at Assets/Edgar/Runtime/Grid2D/Common/FogOfWar/FogOfWarGrid2D.cs:430)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Edgar.Unity.FogOfWarGrid2D:RevealRooms(List1, Nullable1, Boolean) (at Assets/Edgar/Runtime/Grid2D/Common/FogOfWar/FogOfWarGrid2D.cs:267)
Edgar.Unity.FogOfWarGrid2D:RevealRoomAndNeighbors(RoomInstanceGrid2D, Nullable`1, Boolean) (at Assets/Edgar/Runtime/Grid2D/Common/FogOfWar/FogOfWarGrid2D.cs:251)
FOGTrigger:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/FOGTrigger.cs:28)```
OndrejNepozitek commented 2 years ago

Hello! Are you using the latest version of Edgar? What version of Unity do you have?

Are you doing something non-standard with the generator? Because the error looks like your room data got somehow corrupted and it's weird that it would happen only after the Fog of War is trying to reveal the room.

How are you running your setup? Is it all while in play mode or are you generating your level inside the editor (without play mode) and then entering the play mode with an already generated level? Because that could at least lead to some weird serialization issue.

Does the error happen right when you generate the level or do you have to do some extra steps?

Does the FogOfWar example that's inside the examples folder work for you?

hugojobe commented 2 years ago

Hi I use the latest version, yes and I have Unity 2020.3. I think I don't do something strange in my rooms, they look like a square or L-shapedCapture d’écran 2022-08-24 230206 The error happened after I added the FOW component and all it's setup... I generate my rooms in play mode. The error happen right after room generation and, I think, before or while FOW generation.

Thanks

OndrejNepozitek commented 2 years ago

After the error happens, can you please look at the "Generated Level" game object and there's a field called Room instances and in each room instance there's Outline Polygon -> Points:

image

Your error indicates that there's a room instance which doesn't have at least 4 points in the array. Can you please check if you can find such room?

hugojobe commented 2 years ago

All my rooms have 4 points or more...

I have the error even with 1 room in my level :

image
OndrejNepozitek commented 2 years ago

Weird. Now I suspect there's a problem inside your FOGTrigger script. Can you please show me the insides of the script? I suspect that there might be some serialization issues or something like that.

Or if you can just zip the whole project (the Assets folder should suffice) and send it to me that could also help. It's always quite hard to do this "remote debugging".

hugojobe commented 2 years ago

I'll send you the whole project by email :) Wait a little bit while I upload all the files

OndrejNepozitek commented 2 years ago

I think I found the problem. In your room template prefabs, the RoomInfo (Grid2D) component is attached to the root game object of the prefab. This later messes up the actual RoomInfo (Grid2D) component that should only be added after a level is generated. In turn, your FOGTrigger script somehow uses an uninitialised RoomInstance where the outline polygon is empty.

The solution is to go through your room templates and remove the RoomInfo (Grid2D) component from the root game objects. After that, it should work.

Let me know if this fixes it for you!

hugojobe commented 2 years ago

I works thanks !