0 votes

Since there are some limitations (like a signal in editor cannot be connected to a child of a packed scene), I would like to have a generic script which will proxy all method calls (probably only custom methods, since I imagine proxying init or _ready might cause issues, if it's even possible).

I found out there is a _get_property_list to override properties, but I didn't find anything for get_method_list.

How to write a script which will proxy all method calls to a script on its first child?

in Engine by (126 points)

1 Answer

0 votes

As far as I know it is not possible to directly proxy method calls. There is no function similar to _get which works for methods.

What you could instead do, depending on your exact situation, is:

  • Implement each of the methods in the proxy class.

  • Add a single generic function call_function, which works like callv but which can also proxy methods.

  • Generate a proxy script at runtime with Script. This is probably a terrible idea though.


You also mention:

Since there are some limitations (like a signal in editor cannot be connected to a child of a packed scene)

Is there any particular reason you cannot use Object.connect? It sounds like that is what you need.

by (16 points)

Is there any particular reason you cannot use Object.connect? It sounds like that is what you need.

I am not sure how would I do that in an universal way. I have an instance of a scene (packed scene) in my level scene, but because "instance variants" created via Editable Children (e.g. a door with a different texture and collider) cannot be saved as a scene directly (Save branch as scene -> This operation can't be done on instanced scenes.), I have to wrap this customized scene instance in another node (e.g. Node2D) and save that as a scene (so it can be reused). So I have a hierarchy level -> wrapper -> door with open method. I haven't found a generic way how to allow using the wrapper (e.g. connect button to a door.open inside wrapper) without either manually writing proxy scripts (a bit tedious) or not using a wrapper and manually creating on-the-fly desired door variant (a lot more code [using descriptor objects, manual loading of assets, converting it to tool script so it is visible which variant is being used] and much more difficult to code properly, e.g. not loading animations and other assets of all doors when I want just one).

My goal is to have several variants of some scene (e.g. a door) which can be used from editor (without writing code), so a level designer can use it.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.