Skip to content
RustPluginGenerator

OnEntityVisibilityCheck

OnEntityVisibilityCheck is called from BaseEntity's IsVisible RPC test to decide whether a player may see an entity, and a returned bool becomes the visibility result directly.

Signature
object OnEntityVisibilityCheck(BaseEntity entity, BasePlayer player, uint id, string debugName, float maximumDistance)

Parameters

Hook parameters
ParameterTypeDescription
entityBaseEntityThe BaseEntity whose visibility for the given player is being tested, usually an entity with a server RPC (storage, doors, signs, deployables).
playerBasePlayerThe BasePlayer who is running the visibility test, i.e. the client that would see or not see the entity.
iduintThe RPC identifier being tested (the network message the client asks about); it comes from the visibility test request.
debugNamestringA name tag for the visibility test, useful for debugging which check triggered the hook.
maximumDistancefloatThe maximum distance the visibility test allows before it fails; entities behind it are treated as out of range.

Return value

Return null to let the game continue with its own line-of-sight check and default distance rules. Return a bool to short-circuit the original method: the returned value is used as the visibility result, so true marks the entity visible to that player and false marks it hidden without any further physics test.

How it works

The hook fires from BaseEntity.RPC_Server.IsVisible.Test, the server-side handler for the RPC a client sends when it wants to know whether a specific entity should be rendered. It runs before the server does its own work: a null entity or player is rejected first, then Oxide calls OnEntityVisibilityCheck with the entity, the requesting player, the RPC id, a debug name and the maximum distance the test allows. If your method returns a bool, that value replaces the result and the game's line-of-sight check further down is skipped entirely, so returning true forces the entity visible and false hides it. Returning null lets the normal physics test run. This is a per-client, potentially frequent hook, so keep it cheap and avoid logging inside it. Because it is a pre-check on a targeting RPC, you can use it to hide or show entities selectively, but remember the client usually already knows the entity exists from network updates; this controls the visibility response, not spawn.

Example plugin: Hide stashes from everyone except their owner

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

namespace Oxide.Plugins
{
    [Info("Stash Visibility Owner Only", "RustPluginGenerator", "1.0.0")]
    [Description("Hides stashes from players who do not own them using the visibility check hook.")]
    public class StashVisibilityOwnerOnly : RustPlugin
    {
        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Only owner can see stash")]
            public bool OwnerOnly { get; set; } = true;
        }

        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);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Hidden"] = "That stash is not visible to you.",
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args)
            => string.Format(lang.GetMessage(key, this, userId), args);

        private object OnEntityVisibilityCheck(BaseEntity entity, BasePlayer player, uint id, string debugName, float maximumDistance)
        {
            if (!config.OwnerOnly) return null;
            if (entity == null || player == null) return null;
            if (!(entity is StashContainer)) return null;

            if (entity.OwnerID == player.userID.Get() || player.IsAdmin)
                return null;

            return false;
        }
    }
}

The plugin hooks OnEntityVisibilityCheck and looks at the entity being tested. If it is a StashContainer, the plugin compares the entity's OwnerID against the requesting player's id. When the ids differ and the player is not an admin, it returns false to hide the stash from that client; otherwise it returns null so the normal visibility test still applies and the owner (or an admin) sees the stash. A config toggle (Only owner can see stash) lets admins turn the rule off. The entity and player are null-checked before any comparison.

Common use cases

  • Owner-only deployable visibility

    Suppress the visibility test for entities the requesting player does not own, such as stashes or private containers.

  • Team-aware hiding

    Allow a team to see each other's entities by checking player.currentTeam against the entity owner's team before returning a bool.

  • Admin debugging of visibility

    Use debugName and maximumDistance to force visibility true for admins so they can inspect far-away or spoofed entities.

Pitfalls

  • Never return a non-bool

    Oxide only short-circuits when the returned object is a bool; returning any other type falls through to the game's path and can confuse readers. Return null explicitly to keep the default.

  • High call volume

    This fires per client visibility request, so avoid string building, permission lookups and logging. Cache flags you need once in Init or a permission file.

  • Does not stop the entity existing

    Hiding through this hook only affects the visibility result, not network spawn or the player's knowledge of the entity; do not rely on it for security-sensitive concealment.

Build a plugin with OnEntityVisibilityCheck

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

Prompt: Owner-only deployable visibility using the OnEntityVisibilityCheck 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 OnEntityVisibilityCheck

Generate