How get instance using instance id

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By johnguild26

My current script works using for loop of instances, but is there any easier or lighter approach like get_node_by_instance_id(id) ?
Ived checked the documentation Node Section but did not find any.

Anyway here’s my current script:

extends Node2D

var selected = null
var entity_nodes = []

func _ready():
    entity_nodes = get_tree().get_nodes_in_group("entities")

func pick(instanceId):
    selected = instanceId

func drop():
    for entity in entity_nodes:
	    if entity.get_instance_id() == selected:
    selected = null
:bust_in_silhouette: Reply From: jgodfrey

You’re looking for instance_from_id()

See here for details:

Thanks mate, Im still new and getting around the docs. very helpful

johnguild26 | 2020-10-21 00:06