Implementation:Google deepmind Mujoco mj name2id
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, Model_IO |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
Concrete tool for looking up model element IDs by name provided by the MuJoCo C API.
Description
The mj_name2id function searches the compiled model's name table for a matching object name and returns its integer ID. It performs a linear scan through the names for the specified object type.
Usage
Call after loading a model to find specific elements by their XML-defined names. Returns -1 if the name is not found.
Code Reference
Source Location
- Repository: mujoco
- File: src/engine/engine_name.c
- Lines: 240-260
Signature
int mj_name2id(const mjModel* m, int type, const char* name);
Import
#include <mujoco/mujoco.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Compiled model |
| type | int | Yes | Object type enum (e.g., mjOBJ_BODY, mjOBJ_JOINT, mjOBJ_KEY) |
| name | const char* | Yes | Object name to search for |
Outputs
| Name | Type | Description |
|---|---|---|
| return | int | Object ID (>= 0 if found, -1 if not found) |
Usage Examples
#include <mujoco/mujoco.h>
mjModel* m = mj_loadXML("humanoid.xml", NULL, error, 1000);
// Find body ID by name
int torso_id = mj_name2id(m, mjOBJ_BODY, "torso");
if (torso_id >= 0) {
printf("Torso mass: %f\n", m->body_mass[torso_id]);
}
// Find keyframe by name
int key_id = mj_name2id(m, mjOBJ_KEY, "stand");
if (key_id >= 0) {
mj_resetDataKeyframe(m, d, key_id);
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment