Navigation
Browse the developer docs

FH2 Mod Platform for .NET

World

Cars on the road, the nearest ones, time of day and the map waypoint.

By Bartholomew Ho (qiangqiang101) · MIT license · v0.12.0 · 15 Nov 2026 · repository · original page

On this page

The world around you: every car on the road, the nearest ones, the time of day and how fast it passes, and the waypoint you've set on the map.

Thread: game thread only (Game.Tick, Game.Run, an ANNA entry). Waypoint can be read from any thread.

Example

Two ANNA menu entries: one tells you how far the nearest Drivatar is, one sets the time to noon.

protected override void OnInit()
{
    ANNA.Menu.Add("Nearest Drivatar", () =>
    {
        var mine = Player.Car;
        var other = World.GetNearestVehicle(kind: VehicleKind.Drivatar);
        if (mine is null || other is null) return;
        UI.Notify(other.Model?.ShortName ?? "A car", $"{mine.DistanceTo(other):F0} m away");
    });
    ANNA.Menu.Add("Noon", () => World.TimeOfDay = TimeSpan.FromHours(12));
}
Protected Overrides Sub OnInit()
    ANNA.Menu.Add("Nearest Drivatar",
        Sub()
            Dim mine = Player.Car
            Dim other = World.GetNearestVehicle(kind:=VehicleKind.Drivatar)
            If mine Is Nothing OrElse other Is Nothing Then Return
            UI.Notify(If(other.Model?.ShortName, "A car"), $"{mine.DistanceTo(other):F0} m away")
        End Sub)
    ANNA.Menu.Add("Noon", Sub() World.TimeOfDay = TimeSpan.FromHours(12))
End Sub

Members

Properties

MemberWhat it does
Vehicles (property, get, IReadOnlyList<Vehicle>)Every car the game updated last frame: yours, Drivatars, traffic.
TimeOfDay (property, get/set, TimeSpan)The time of day, as the world's clock has it. Setting it moves the sun straight away. Values past 24 hours (or below 0) wrap round.
TimeScale (property, get/set, float)How fast the clock runs: 1 is the game's own pace, 0 stops it. Values below 0 are set as 0.
Waypoint (property, get, Vector3?)The waypoint you've set on the map, or null if there's none (or the HUD isn't up to say, in the garage for example). It's on the road where the sat-nav's route ends, with the ground's height; or the map's pin when there's no route. Any thread.
LightLevel (property, get, float)How much light there is where you're driving, as the game's lighting has it. It drops to a fifth or less in a tunnel; compare it with a moment ago rather than with a fixed number. -1 if it can't be read. Any thread. New in 0.12.0.

Methods

MemberWhat it does
GetNearestVehicle(Vector3? from = null, VehicleKind? kind = null) → Vehicle?The car nearest from (your car's position if you leave it out), not counting yours. Only cars of kind, if you give one. Null if there's none.
GetVehiclesInRange(float radius, Vector3? from = null) → IReadOnlyList<Vehicle>Cars within radius metres of from (your car if you leave it out), nearest first, not counting yours.
PrepareRoutes()Call it from OnInit if you use RouteToNearest: it hooks the game's navigation module as the game starts. Only mods that call it get the hook, because FH2 ANNA turns its own routes off when another mod hooked that module first. New in 0.12.0.
RouteToNearest(Destination destination) → boolSets the GPS route to the nearest Event, BucketList, RoadTrip stop, BonusBoard (found, not smashed) or BarnFind rumour, as ANNA's voice commands did. Call PrepareRoutes from OnInit first. False if there's none. Game thread only. New in 0.12.0.

Notes

  • Like every Vehicle, the cars you get here are only valid for this frame. Don't keep them between ticks.
  • If you leave out from and you're not driving (no Player.Car), GetNearestVehicle returns null and GetVehiclesInRange returns an empty list.
  • TimeOfDay and TimeScale throw an InvalidOperationException when the world isn't loaded.
  • Waypoint throws an InvalidOperationException when the game isn't ready yet (still loading, or a game build the SDK doesn't know).
  • On a game build where the sat-nav isn't as expected, Waypoint is always null and platform.log says so ("World.Waypoint off").
  • Distances and positions are in metres: X and Z across the map, Y up.
  • Using the game-thread members from another thread throws an InvalidOperationException that says to use Game.Tick or Game.Run.

See also

Copied from the wiki page World at commit 7396a07 · MIT license
MIT License

Copyright (c) 2026 Bartholomew Ho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.