Table of Contents

Method FindNearestInteractive

Namespace
GrindFest
Assembly
GrindFest.dll

FindNearestInteractive(string, string, string, float)

Finds the nearest interactive object (like chests or shrines) that matches the name criteria.

public static InteractiveBehaviour FindNearestInteractive(string name1 = "", string name2 = null, string name3 = null, float maxDistance = 15)

Parameters

name1 string

Primary name to search for. Object name must contain this string. If empty, matches any name.

name2 string

Optional secondary name to search for. If provided, object name must contain either this or name1.

name3 string

Optional tertiary name to search for. If provided, object name must contain either this, name2, or name1.

maxDistance float

Maximum search distance from the hero. Defaults to 15 units.

Returns

InteractiveBehaviour

The nearest InteractiveBehaviour that matches the criteria, or null if no matching object is found.

Remarks

This method searches for objects on the Interactable layer, which includes:

  • Chests containing loot
  • Shrines providing buffs
  • NPCs for trading and dialogue
Find and open nearest chest:
var chest = Hero.FindNearestInteractive("Chest");
if (chest != null)
{
    if (Hero.InteractWith(chest))
    {
        Hero.Say("Found and opened a chest!");
    }
}
Find and use nearest shrine:
var shrine = Hero.FindNearestInteractive("Shrine");
if (shrine != null)
{
    Hero.InteractWith(shrine);
    Hero.Say($"Used {shrine.name}!");
}

FindNearestInteractive(Predicate<InteractiveBehaviour>, float)

Finds the nearest interactive object (like chests or shrines) that matches the name criteria.

public static InteractiveBehaviour FindNearestInteractive(Predicate<InteractiveBehaviour> predicate, float maxDistance = 15)

Parameters

predicate Predicate<InteractiveBehaviour>
maxDistance float

Maximum search distance from the hero. Defaults to 15 units.

Returns

InteractiveBehaviour

The nearest InteractiveBehaviour that matches the criteria, or null if no matching object is found.

Remarks

This method searches for objects on the Interactable layer, which includes:

  • Chests containing loot
  • Shrines providing buffs
  • NPCs for trading and dialogue
Find and open nearest chest:
var chest = FindNearestInteractive("Chest");
if (chest != null)
{
    if (InteractWith(chest))
    {
        Say("Found and opened a chest!");
    }
}
Find and use nearest shrine:
var shrine = FindNearestInteractive("Shrine");
if (shrine != null)
{
    InteractWith(shrine);
    Say($"Used {shrine.name}!");
}