Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RID Objects are always "Invalid RID" #33797

Open
zaksnet opened this issue Nov 21, 2019 · 10 comments
Open

RID Objects are always "Invalid RID" #33797

zaksnet opened this issue Nov 21, 2019 · 10 comments

Comments

@zaksnet
Copy link
Contributor

zaksnet commented Nov 21, 2019

Godot version:
Beta 1
OS/device including version:
Windows 10 1903
Issue description:
No matter which function i use, the RID object always gives Invalid RID.
Steps to reproduce:
Try any of these:
var ps_rid = get_viewport().get_world().get_space() # ps_rid is Invalid RID
var vs_rid = get_viewport().get_world().get_canvas() # vs_rid is Invalid RID

var rigidBody = RigidBody2D.new()
var rb = rigidBody.instance()
add_child(rb)
print(rb.get_rid()) # prints Invalid RID

image
image
image

@zaksnet zaksnet changed the title Invalid RID RID Objects are always "Invalid RID" Nov 21, 2019
@bojidar-bg
Copy link
Contributor

The only mention of Invalid RID in the code is in the Inspector (and mostly makes sense, as the RID is valid in the debugged game, not in the editor):

void EditorPropertyRID::update_property() {
RID rid = get_edited_object()->get(get_edited_property());
if (rid.is_valid()) {
int id = rid.get_id();
label->set_text("RID: " + itos(id));
} else {
label->set_text(TTR("Invalid RID"));
}
}

I don't think the print statement can result in Invalid RID, it should print [RID] from what I can see.

@zaksnet
Copy link
Contributor Author

zaksnet commented Nov 21, 2019

@bojidar-bg Alright, that makes sense, BUT, trying to call any kind of method on that RID object just gives me:
image
The image is from:

	var vs_rid = get_viewport().get_world_2d().get_canvas()
	var ci_rid = vs_rid.canvas_item_create()

I havent been able to call any kind of method on any returned RID object.

I don't think the print statement can result in Invalid RID, it should print [RID] from what I can see.

Yes, you are right, it returns [RID]. I have also attached an image with this.

EDIT: Of course, that would make sense if RID is just a number(?). But then, how can i use the RID of the visual server, for example, to create a canvas item in it?

@zaksnet
Copy link
Contributor Author

zaksnet commented Nov 21, 2019

The only mention of Invalid RID in the code is in the Inspector (and mostly makes sense, as the RID is valid in the debugged game, not in the editor):

void EditorPropertyRID::update_property() {
RID rid = get_edited_object()->get(get_edited_property());
if (rid.is_valid()) {
int id = rid.get_id();
label->set_text("RID: " + itos(id));
} else {
label->set_text(TTR("Invalid RID"));
}
}

I don't think the print statement can result in Invalid RID, it should print [RID] from what I can see.

NVM, i think my confusion was just with the Invalid RID. using VisualServer.canvas_item_create() with the visual server singleton instead of the RID seems to work

@zaksnet
Copy link
Contributor Author

zaksnet commented Nov 21, 2019

Looking back, the problem started when i was following the docs in an attempt to replicate:

func _body_moved(state, index):
    # Created your own canvas item, use it here.
    VisualServer.canvas_item_set_transform(canvas_item, state.transform)

func _ready():
    # Create the body.
    var body = Physics2DServer.body_create()
    Physics2DServer.body_set_mode(body, Physics2DServer.BODY_MODE_RIGID)
    # Add a shape.
    var shape = RectangleShape2D.new()
    shape.extents = Vector2(10, 10)
    # Make sure to keep the shape reference!
    Physics2DServer.body_add_shape(body, shape)
    # Set space, so it collides in the same space as current scene.
    Physics2DServer.body_set_space(body, get_world_2d().space)
    # Move initial position.
    Physics2DServer.body_set_state(body, Physics2DServer.BODY_STATE_TRANSFORM, Transform2D(0, Vector2(10, 20)))
    # Add the transform callback, when body moves
    # The last parameter is optional, can be used as index
    # if you have many bodies and a single callback.
    Physics2DServer.body_set_force_integration_callback(body, self, "_body_moved", 0)

Physics2DServer.body_add_shape(body, shape) That line is wrong. shape variable is not an RID. You have to get the RID first using get_rid(). But then i saw the Invalid RID in the debugger and i assumed that was the error 😵.
So to sum up, first there needs to be a fix for the Invalid RID message and second for the docs. I will make the changes myself later with a PR.
Thanks @bojidar-bg 👊

@Zylann
Copy link
Contributor

Zylann commented Nov 22, 2019

Physics2DServer.body_add_shape(body, shape) That line is wrong. shape variable is not an RID. You have to get the RID first using get_rid()

Isn't Godot actually converting into a RID if the parameter inherits Resource? That may add to the confusion but I think that's what happens.

@zaksnet
Copy link
Contributor Author

zaksnet commented Nov 22, 2019

Physics2DServer.body_add_shape(body, shape) That line is wrong. shape variable is not an RID. You have to get the RID first using get_rid()

Isn't Godot actually converting into a RID if the parameter inherits Resource? That may add to the confusion but I think that's what happens.

@Zylann Yeah, i think you're right 😵😵. Now I'm lost.

@ThereIs0Spoon
Copy link

This might be just restating what has been already said, but I see an identical behaviour on the following:

var D:DynamicFont
var R:RID
var i:int

....
R = $Sprite.get_rid()
i = R.get_id()
print(R)
print(i)
....
D.size = 24
D.draw(R, Vector2(0.0, 0.0), "abc123")

In the output window I get:
[RID]
151
and get the following error from DynamicFont.draw()
immagine

@Xrayez
Copy link
Contributor

Xrayez commented Feb 19, 2020

Furthermore, if you somehow expose RID property, it won't be saved properly in a tscn, which will lead to parse error on opening. I've only stumbled upon this while accidentally exposing an RID as a property using C++ with some combination of property hints and usage. Exporting RID via GDScript and saving works alright.

@Listwon
Copy link
Contributor

Listwon commented Sep 15, 2020

I'm trying to use Physics2DServer.area_set_area_monitor_callback and with breakpoint inside callback function I always get Invalid RID in inspector view.
Invalid RID

Sample project in Godot 3.2.2
bullet-shower.zip

@FrederickDesimpel
Copy link

Creating and working with RIDs directly using VisualServer works, so that Invalid RID message in the inspector is indeed misleading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants