City Skylines District tool in UE4?

Hi, I’m making an RTS in UE4 and I’m trying to create nation territories that can change shape throughout the game (Like the District tool in City Skylines).

I’m thinking about using splines to do this, but am completely stumped.
Any help or tips towards solving this problem would be great.

Thanks.

Exactly like this: Cities: Skylines Dev Diary Review - Part 8 ► Districts and Policies ◀ [With Subtitles] - YouTube

You need to calculate a convex hull, and then you can do with it whatever you want, e.g. draw it.

There are certain algorithms, you can see here:Convex hull algorithms - Wikipedia

The simplest one I think is this algorithm here: Convex hull algorithms - Wikipedia

How could I transfer this algorithm in to UE4? Thanks btw

Also, I don’t think a convex hull is exactly what I’m looking for. A convex hull wouldn’t be able to create the type of freeform shape I need.

You first have to create a point list from what you have. The points could be the actor positions, but that is not very precise. You can work with bounding boxes there too.

So you have your BorderManager or something object. There you have a function. It calculates inside points, and with the algorithm then calculates the vertices of the boundary polygon. You can save them. Everyone can query these e.g. for drawing.

You don’t need to calculate it every tick, only recalculte when the user places a new building.

Yeah, I’m looking to for the player to be able to draw really free form shapes, like even write your name in territory if you wanted to.

Well I am overasked here. Maybe try it in a forum especially for algorithms.

Anyone came up with a solution for this problem :slight_smile: ?

I am able to implement this using UE::Geometry::TGeneralPolygon2, which is basically a vector of FVector2d that forms the perimeter of the polygon and its internal holes. The same module also provides useful functions for polygon union, difference, triangulation etc.

I then render the polygon district with a DynamicMesh.