Reputation: 11
first post so please go easy on me!
I'm working on porting a board game into Godot as a learning project. The board game map is made up of a number of irregular polygons (some convex, some concave). Currently I have a few different scenes I'm working on:
I have a "LandRegion" scene, an Area2D which contains a Polygon2D and a CollisionPolygon2D as well as a few other nodes for other parts of the game logic. My understanding is I need the Polygon2D to display the shape, and the CollisionPolygon2D to make it interactable. There is an attached "LandRegion" script which takes in a Vector2 array and passes it on to both the Polygon2D and the CollisionPolygon2D to define the shape of each. (They are the same shape).
I have a "LandMap" scene, a container which instantiates a number of "LandRegion" scenes as children using hardcoded array of Vector2 arrays to define the shape of each region.
A "Main" scene, which contains an instance of the LandMap as well as several other parts of the game I've been working on.
**My problem: ** As is, my LandMap generates the shapes of each LandRegion at runtime, so I cannot see or edit the map in Godot's 2D editor. I'd really like to be able to do that, but I don't know how to set it up so I could.
I have tried adding a "shape" property (array of Vector2D) to the Area2D which it passes down to its children and which is "exported" to the editor. However, since editing this "shape" array only affects the child nodes "Polygon2D" and "CollisionPolygon2D" at runtime, I cannot preview the shapes that these Vector2D arrays would create. This is really what I'd like to be able to do if possible.
Upvotes: 1
Views: 503
Reputation: 40285
First of all, the evident: You could edit the polygons in the editor.
I presume that the reason you don't do that is because they are different. You could make an scene for each shape (they can still share scripts and other resources), furthermore, you could do this with scene inheritance.
Assuming that is not a solution for you, you could make your script in the editor by adding the @tool
annotation. You can then use Engine.is_editor_hint()
to find out if the code is running on the editor or not (which is important because the code running in the editor would be modifying the project, so you want to be careful what code runs on the editor and what code does not). See Running code in the editor.
I'll take the opportunity to remind you to use version control.
By allowing your code to run on the editor, the shape property should run in the editor and you would be able to see the change reflected in the other nodes.
Upvotes: 0