如何获取存储场景的目录?
我有一个名为prination1
(res://scenes/characters/character1.tscn)
的场景 它是在另一个场景中进行实例的lact1
(res://scenes/levels/level1.tscn)
,我需要获取字符场景的目录
。 br> print(get_tree()。edited_scene_root.filename.get_base_dir())
但此prints
res:// speces/latver
而我需要打印
res:// sceets/cartial
I have a scene called Character1
( res://Scenes/Characters/Character1.tscn )
and it is instanced in another scene Level1
( res://Scenes/Levels/Level1.tscn )
and I need to get the directory of the scene of Character1
I tried this inside the script of Character1:print(get_tree().edited_scene_root.filename.get_base_dir())
But this prints
res://Scenes/Levels
Whereas I need it to print
res://Scenes/Characters
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了安全:
文件名仅设置为场景的最高节点。参见
否则是一个空字符串。
Just for safty:
filename is only set for the topmost node of an scene. See here
Otherwise it is an empty string.
我想我找到了一个解决方案,但我不确定它是否会在任何情况下工作:
I think I found a solution but I'm not sure if it will work in every situation: