-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Add a 'plugin' keyword similar to 'tool' #17592
Comments
I design my plugin's UI through the editor, and I thought of this as well. I likely avoided it by chance so far since my UIs are encapsulated and singleton-free. They basically do nothing if they aren't told to do so by their owner (which doesn't exist within the edited scene so the logic stays idle). Initially I thought to have a way to check in scripts if the scene root was the edited scene root and then discard any logic, but that would be quite cumbersome in addition to the
I guess this is known by the editor, if the scene gets instanced outside of an edited scene root? I think this problem was never encountered before because so far, all editor UI was created by code... but if you think about it, every single C++ node in Godot is implemented in the same situation: they all run in all cases (there is no This mindset for example implies that you should not connect internal signals by code in Do you have an example of an impossible/annoying situation? |
I bumped into something like this too. I have to carefully not save the scene or delete everything from an ItemList that was populated by the script before saving. I also have issues with stuff that needs the plugin reference which is not available in design-time. Signals aren't really a problem unless you connect them as persistent (which wouldn't make much sense anyway). The alternative is not to use the tree callbacks ( I would be satisfied by something to |
@Zylann, I agree that you can split responsibilities in such a way that you avoid the issue, if I have got your point. Probably doable in every situation, but for simple plugins you may prefer to mix UI and logic. |
Now I'm wondering if it wouldn't be better to let plugin writers have something like |
I would just allow both I'm still not sure if a new keyword is the best solution (I'm always wary of adding stuff to GDScript). I can't think of anything else, though. |
We might have it as |
I think this is needed as well, I'm a frequent user of ReferenceRect when designing a GUI so I can visualize empty spaces. However, its based on the Having a |
I'm now having this problem in a constraining situation. I have a dialog window that contains a viewport, and at runtime, I assign its ViewportTexture to a TextureRect in the window. I also modify materials that are used to render that TextureRect too. I cannot think of a workaround that works by design this time. The workaround I have currently just makes things a bit more complicated (having a boolean set externally, or create the TextureFrame at runtime so that it's not saved) EDIT: if is_inside_tree() and get_tree().edited_scene_root:
return This way I can see the EDIT: turns out it... does not work?? I changed my workaround to be: func is_in_edited_scene():
# TODO https://github.com/godotengine/godot/issues/17592
return is_inside_tree() and ((get_parent() is Control) == false) This is obviously very fragile. I'd like a correct version of this to be available somehow :/ |
@Zylann The EditorInterface class has a |
@willnationsdev but that's the problem. It's on |
Would you prefer that |
@willnationsdev probably not something that extreme...
What I would need would be just a way to check if my node inside an edited scene. |
@Zylann is this not part of a plugin? Why not ping the EditorPlugin via signal like I suggested? Is that not an option, or do you find it tedious or something? |
@willnationsdev this is not an option because I can't access the EditorPlugin in the first place (and normally shouldn't). Also, giving access to it in the Edit: |
Been using the following. So far haven't had issues with it since I call it in the root node scripts that need it, but maybe it has holes in it.
|
OMG, for some reason I thought this was a boolean. That will improve my utility function to get that info, then :) static func is_in_edited_scene(node):
if not node.is_inside_tree():
return false
var edited_scene = node.get_tree().edited_scene_root
if node == edited_scene:
return true
while node.get_parent() != null:
node = node.get_parent()
if node == edited_scene:
return true
return false |
# Haven't tested this. X)
static func is_in_edited_scene(node):
var edited_scene = node.get_tree().edited_scene_root
return node.is_inside_tree() and (node == edited_scene or edited_scene.is_a_parent_of(node)) |
Close :) static func is_in_edited_scene(node):
if not node.is_inside_tree():
return false
var edited_scene = node.get_tree().edited_scene_root
if node == edited_scene:
return true
return edited_scene != null and edited_scene.is_a_parent_of(node) Edit: had to also check if the |
I just read in #23651 (comment) there is a bool SceneTree::is_node_being_edited(const Node *p_node) const {
return Engine::get_singleton()->is_editor_hint() && edited_scene_root && (edited_scene_root->is_a_parent_of(p_node) || edited_scene_root == p_node);
} |
The wheel reinvented. |
Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine. The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker. If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance! |
works for me. c# version: if(SourceNode.IsInsideTree() == false)
return false;
var EditedScene = SourceNode.GetTree().EditedSceneRoot;
if(SourceNode == EditedScene)
return true;
return EditedScene != null && EditedScene.IsAncestorOf(SourceNode); |
The problem
While developing plugins you have to add the the
tool
keyword to every script. The problem is that if you open an scene file belonging to the plugin, it runs and if you save it, you are effectively saving a runtime state of the GUI (lists populated, controls enabled/disabled and so on). Because of that I'm having to remove/re-addtool
many times.I know there is
Engine.editor_hint
, but I think that allows only to check if your code is running on the editor (both for editing and a running plugin) instead of as part of a running project.The proposal
Adding a new keyword (let's say
plugin
) that you can use instead oftool
that enables the script only if it's part of a running plugin. In other words, these would be the semantics for all cases:plugin
keyword => Run script only if it has been loaded as part of a running plugintool
keyword => Run script everywhereI think I can implement this myself if is makes enough sense and there's no a good way of achieving it currently.
The text was updated successfully, but these errors were encountered: