-
Notifications
You must be signed in to change notification settings - Fork 0
GameUtil
Kanisuko edited this page May 23, 2026
·
2 revisions
Namespace: ScavLib.util
General-purpose game-state helpers. All methods are safe to call from the
main menu — they handle null game state gracefully and will never throw a
NullReferenceException.
| Member | Type | Description |
|---|---|---|
IsInGame |
bool (property) |
true if PlayerCamera.main exists. |
IsWorldLoaded |
bool (property) |
true if WorldGeneration.world exists and reports a loaded world. Stricter than IsInGame. |
GetWorld() |
WorldGeneration |
The WorldGeneration instance, or null if not loaded. |
GetBody() |
Body |
The player's Body, or null if not in game. |
TryGetBody(out Body body) |
bool |
Try-pattern wrapper around GetBody(). |
GetPlayerPosition() |
Vector2 |
Player world position, or Vector2.zero if not in game. |
if (GameUtil.TryGetBody(out var body))
{
// body is guaranteed non-null here
GameUtil.Log($"Player at {body.transform.position}");
}| Method | Returns | Description |
|---|---|---|
SpawnItem(string id, Vector2 position, float rotation = 0f) |
GameObject |
Spawn an item at a world position. Returns null if the ID is unknown or no world is loaded. |
SpawnItemAt(string id, Transform target) |
GameObject |
Spawn at a Transform's position and rotation. |
SpawnAtPlayer(string id) |
GameObject |
Spawn at the player's feet and auto-pickup if a slot is free. |
// Spawn a bandage and auto-pickup
GameUtil.SpawnAtPlayer("bandage");
// Spawn at a specific world position
GameUtil.SpawnItem("pistol", new Vector2(10f, 5f), rotation: 45f);
// Spawn at a Transform
GameUtil.SpawnItemAt("medkit", someTransform);| Method | Description |
|---|---|
Log(string message) |
Write a message to the in-game developer console. Safe to call before the console is initialized — message is silently dropped. |
Alert(string text, bool important = false) |
Show an in-game alert popup. important: true displays it prominently in the center of the screen. |
Notify(string text, bool important = false) |
Call both Alert() and Log() in one call. Useful for events you want both visible and logged. |
GameUtil.Log("Debug message — visible in console only.");
GameUtil.Alert("Something happened!", important: false);
GameUtil.Notify("Critical event!", important: true);| Method | Returns | Description |
|---|---|---|
IsPointerOverUI() |
bool |
true if the mouse cursor is currently over a game UI element. |
Use this in your MenuWindow.DrawContent() or Update() to avoid
intercepting mouse clicks that are meant for the game UI:
private void Update()
{
if (GameUtil.IsPointerOverUI()) return;
// Handle world-space mouse input here
}