How do I get RID of an instanced node? (I need this to set AABB for MultiMeshInstance )

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

There is get_rid() for resources. But there is no get_rid() for nodes (except, strangely, the single node type CollisionObject2D, which does have it). How do I get RID for any kind of instanced node?

There are many google hits making me think that get_rid() was perhaps a valid node method in Godot 2.0. It isn’t in 3.0.x.

My specific need is to get RID for a MultiMeshInstance to set AABB. Unless someone can tell me otherwise, the only way to set AABB for a node instance (not a mesh) is using VisualServer.instance_set_custom_aabb ( RID instance, AABB aabb ). But I need RID for the MultiMeshInstance to do so.

I did try VisualServer.mesh_set_custom_aabb() on the MultiMesh, but that gives me an error telling me that my MultiMesh is not a Mesh (which I knew already). Setting AABB for the original Mesh used in the MultiMesh does not determine AABB of the MultiMesh or the MultiMeshInstance.

Arghhh… does anyone know how to make the Q&A forum not garble underscores?
The methods I was trying to reference above are as follows (substitute underscore for dash):

Charlie | 2018-09-03 02:29

The need for setting AABB on an instance is stated in the docs for MultiMesh: “Since instances may have any behavior, the AABB used for visibility must be provided by the user.” Annoyingly, there are get_aabb() methods everywhere but no set_aabb() anywhere that I could use (not for MultiMesh or MultiMeshInstance or MultiMeshInstance inherited classes).
The method to do so using VisualServer is referenced here:
Need a way to set a custom AABB per visual instance · Issue #9544 · godotengine/godot · GitHub
Implement per-instance custom bounding box by Zylann · Pull Request #12645 · godotengine/godot · GitHub

However, I’m still stuck since I don’t know how to get the instance RID that I need to use in
VisualServer.instance-set-custom-aabb(RID, AABB).

Charlie | 2018-09-03 03:46

:bust_in_silhouette: Reply From: Zylann

Indeed, the function is missing from the nodes API. This function has to be exposed in GeometryInstance but so far only exists in the server API, so it’s fine if you use that directly instead of nodes but that’s quite impractical for more common use.

I posted an issue: No way to set a custom AABB on GeometryInstance using nodes API · Issue #21758 · godotengine/godot · GitHub

Thanks! I’m glad to know this is being tracked down.

Back to the 1st question, is there some back-door trick (via server or whatever) to get RID for my MultiMeshInstance? I tried RID(obj) but that seems to work only for resources. This led me to think that I am having a conceptual misunderstanding and that RIDs only exist for resources. But then your server method made me think that, yes, they exist for nodes too, even if I can’t figure out how to get one. Is that correct?

Btw, I also tried using MultiMesh RID in your VisualServer.instance-set-custom-aabb(), but that gave me “!instance” errors.

Charlie | 2018-09-04 22:29

RIDs really exist for some nodes that are actually high-level wrappers around VisualServer objects (that includes resources, but not only).

Using on MultiMesh won’t give the expected result because it’s not a GeometryInstance. Here is how I used it in my project: (look at what _mesh_instance actually is)

But again it’s not easy for common usage so it’s just better to have that on nodes too rather than trying to get RIDs to bypass that lack (also I checked Godot 2.1.5, get_rid did not exist for nodes either).

Zylann | 2018-09-04 22:37