Skip to content
RustPluginGenerator

OnGibsSpawned

OnGibsSpawned is called inside ServerGib.CreateGibs right before the finished list of gib entities is returned, after all gibs have been created and collision rules between them applied.

Signature
void OnGibsSpawned(List<ServerGib> gibs, UnityEngine.GameObject creator)

Parameters

Hook parameters
ParameterTypeDescription
gibsList<ServerGib>The list of ServerGib entities created for this death. You can inspect, remove or modify entries before the list is returned to the game.
creatorUnityEngine.GameObjectThe GameObject that produced the gibs (normally the corpse or body part being destroyed). Use it to locate the origin position or identify the source entity.

Return value

The return value is ignored. ServerGib.CreateGibs always returns the list it built, so returning null, true or the list itself does not change the outcome; to influence the game you must mutate the gibs list or the entities it contains.

How it works

This hook fires at the end of ServerGib.CreateGibs, the method the game runs when a character or gib-able entity is destroyed and its body breaks into gibs. It runs after every gib object has been instantiated and after the collisions between the gib colliders have been disabled, so the gibs list is complete. The list holds ServerGib instances; each entry exposes the underlying entity, so you can read positions, prefab names or forward damage state from it. The creator GameObject points at whatever spawned the gibs — typically the dying entity's game object — and is useful for getting a world position with creator.transform.position. Declaring the first parameter as a more specific type would only match when every element is that type; for a list of ServerGib leave it as List<ServerGib>. Because this hook fires for every gib-producing destruction on the server, keep the body cheap: no logging, no allocations in a loop, and no per-gib string building unless it is gated behind a guard.

Example plugin: Cap the number of gibs spawned per death

GibLimit.cs
using UnityEngine;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using Rust;

namespace Oxide.Plugins
{
    [Info("GibLimit", "RustPluginGenerator", "1.0.0")]
    [Description("Caps how many gib entities a single death can spawn.")]
    public class GibLimit : RustPlugin
    {
        private class PluginConfig
        {
            [JsonProperty("Maximum gibs per death")]
            public int MaxGibs = 6;
        }

        private PluginConfig config;

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        private void OnGibsSpawned(List<ServerGib> gibs, UnityEngine.GameObject creator)
        {
            if (gibs == null || gibs.Count <= config.MaxGibs) return;

            for (int i = gibs.Count - 1; i >= config.MaxGibs; i--)
            {
                ServerGib gib = gibs[i];
                if (gib == null) continue;

                gibs.RemoveAt(i);

                if (!gib.IsDestroyed)
                {
                    gib.Kill();
                }
            }
        }
    }
}

The plugin limits how much clutter a single death produces by trimming the gibs list inside OnGibsSpawned. It reads a configurable maximum from the config file and, if the list is longer, destroys the extra ServerGib entities with Kill() and removes them from the list so they are never returned to the game. Because the hook fires for every gib spawn, the body only does work when the count exceeds the configured limit; there is no logging or string formatting on the hot path. A short config class keeps the cap adjustable without recompiling, and Unload is trivial since no timers or UI are used.

Common use cases

  • Reduce server load from large gib bursts

    Trim the gib list for high-population servers to cut physics and entity count after big firefights or raids.

  • Tag or track gib origins

    Read the creator's position to record where a death happened, for kill feeds, spawn protection logic or map heatmaps written to oxide/data.

  • Suppress gibs for special cases

    Check the creator's identity or prefab name and kill all gibs, for example for event NPCs where body parts would despawn awkwardly.

Pitfalls

  • The hook is hot

    It runs on every gib-producing death. Avoid PrintWarning, string concatenation and LINQ here; iterate with a plain for loop and bail out early when nothing needs changing.

  • Removing entries does not despawn them

    Dropping a ServerGib from the list only stops the game from using that list entry. Call Kill() on the entity as well or the gib object stays in the world.

  • creator can be null or unexpected

    Some destruction paths may pass a GameObject that is not the player or entity you expect. Null-check creator and its transform before reading a position.

Build a plugin with OnGibsSpawned

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Reduce server load from large gib bursts using the OnGibsSpawned hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnGibsSpawned

Generate