Skip to content

Class: RoadContainer

Patrick W. Crawford edited this page Oct 3, 2024 · 3 revisions

A RoadContainer is analogous to a single "road", containing two or more RoadPoints, and is a child of RoadManager (or, the scene root, if a saved subscene).

roadcontainer editor

Usage

These nodes should always be children (direct or indirect) of a RoadManager. This way, settings on the RoadManager propagate down to all RoadContainers, and functions like "Refresh all roads" can properly work on all RoadContainers in the scene.

Once a RoadContainer is selected, you can add RoadPoints by either going to the Roads menu ("2x2 Road" or "RoadPoint"), or by entering the Add mode of the plugin. You can do this by pressing the green + icon in the 3D viewport panel, similar to that of a 3D Path. You can now click to add more RoadPoints as children of this container.

Be aware that a RoadContainer is a spatial, so you can rotate or translate the entire RoadContainer as one chunk. You are not recommended to scale RoadContainers or their children. Use the "RoadWidth" property if you want to change the physical size of Roads.

A RoadContainer also defines the material for all of its children RoadPoints. You can drop in any material resource you like. A template in the project is provided if you want to make custom road textures. See the tutorial here for more details. Note that a specific texture layout is used in order to accomplish procedural texturing.

Public functions

The following are functions that may be useful to call during runtime. For more functionality, look at the public functions in the RoadContainer class itself. If you are looking to implement your own procedural generation of roads during the game runtime, check out the demo/procedural_generator/ project and its readme.

  • rebuild_segments(clear_existing=false): The main function to reconstruct all geometry for this RoadContainer. This should be automatically called when relevant via plugin "dirty" flags, but if RoadManager.auto_refresh is off, you may want to call this to rebuild everything to construct the visual and collision meshes.
  • update_edges: Update export variable lengths and counts to account for connection to other RoadContainers. The "Edges" variable is an array of RoadPoints with only one connection, meaning the represent the start or end of a road, and thus are eligible to be the "edge" of this RoadContainer and aligned with the "edge" of another RoadContainer. This is called and maintained automatically by the plugin, but in some cases you may need to forcefully ensure it's updated when dealing with creating connections between different RoadContainers.
  • get_roadpoints: Get the list of all RoadPoints inside this container. Set skip_edge_connected to true skip any RoadPoints which are at the edge of the container and also connected to another container.
  • get_segments: Get the list of all RoadSegments in this container. You could then iterate over all of these RoadSegments to identify all RoadLanes for instance.
  • snap_to_road_point: Transforms the first input (RoadPoint)'s parent RoadContainer such that this input RoadPoint becomes perfectly aligned and attached to the target RoadPoint (second input)
  • get_transform_for_snap_rp: Utility function to execute the above. Useful if you want to manually move the target's parent yourself. Be sure to "connect" the RoadPoints together if you do so (function of the RoadPoint class).
  • get_open_edges: Utility to get the list of all open "edges" in the container, where an edge is one direction of a RoadPoint which is not yet connected to another RoadPoint.
  • get_connected_edges: Utility function to find which edges of a container represent being connected to another RoadContainer (which could be another scene).

Settings

Script Variables

  • material_resource: The material to add to the RoadSegment meshes (which are placed between RoadPoints on the fly)
  • density: Determines the distance in meters between loopcuts of a RoadSegment mesh. A lower number means a higher poly mesh and smoother curves. See bake_internal described here.
    • Note: This value is set to -1 by default, indicating it will inherent from the parent RoadManager's set density.
  • create_geo: Generate procedural road geometry. If off, it indicates the developer will load in their own custom mesh + collision.
  • use_lowpoly_preview: If enabled, will use lower density roads in viewport while a transform is in progress. The full poly mesh will be used as soon as the placement is complete.
  • create_edge_curves: Whether to create approximated curves to fit along the forward, reverse, and center of the road. Visible in the editor, useful for adding procedural generation along road edges or center lane.
  • generate_ai_lanes: If enabled, RoadLane paths will be added to represent each lane of the roads being constructed for the RoadSegment child(ren) of this RoadPoint. Its primary use is for AI path following of a specific lane, including merges/splits.
  • ai_lane_group: Optional field to auto assign generated RoadLanes to a group of this name on runtime. Useful if you need to fetch all available RoadLanes.
  • auto_free_vehicles: Pass through to each RoadLane on whether to auto free all registered vehicles on _exit_tree. Useful to let the road generator handle any vehicles on a road segment to be cleaned up but is not a direct child (which would require re-parenting as vehicles travel between segments).
  • collider_group_name: Group name to assign to the static bodies created within a RoadSegment.
  • collider_meta_name: Meta property name to assign to the static bodies created within a RoadSegment, value will always be true. Useful to assign friction values or other properties picked up from actor raycasts; more efficient that using collider_group_name as there's no need to look up membership within an entire group as the collider object directly has the meta value.
  • debug: Enables additional debugging output information.
  • draw_lanes_editor: Automatically display the sawtooth visual for all RoadLanes in the editor. Will do nothing, if generate_ai_lanes is not enabled.
  • draw_lanes_game: Automatically display the sawtooth visual for all RoadLanes in the game runtime. Will do nothing, if generate_ai_lanes is not enabled.

Export variable arrays: The following should not be manually edited. They are for private use only by the plugin, allowing the connection between containers even of scenes saved to different scene files. You can inspect them, however, to see how connections between different RoadContainers are set up.

  • edge_containers: Paths to other containers, relative to this container (self)
  • edge_rp_targets: Node paths within other containers, relative to the target container (not self here)
  • edge_rp_target_dirs: Direction of which RP we are connecting to, used to make unique key along with the edge_rp_targets path above. Enum value of RoadPoint.PointInit
  • edge_rp_locals: Node paths within this container, relative to this container
  • edge_rp_local_dirs: Local RP directions, enum value of RoadPoint.PointInit

Current support: Godot 3.5+ Godot 4 planned for v1.0 of this addon (details)

Wiki pages

Clone this wiki locally