#Is this a good way of peeking at a packed scene?

25 messages · Page 1 of 1 (latest)

trail flax
#

So I have some packed scenes that I want to instantiate into the game world.

Before instantiating them though, I want to get some info from them. This is for menus and previews since these objects are being put into a grid menu of buyable objects so I'm trying to see the sprite, price, name, etc.

So my current method is this:

  # Do a bunch of stuff
instance.queue_free()```

So I'm instantiating the object, looking at a bunch of info, and then using `queue_free` to get rid of that instance, never adding it to the tree.

Is this a good way of going about what I'm doing?

I'm not having any issues so far, but I'm still fairly new to Godot and want to make sure I'm not setting up my project to implode with some really stupid ideas 😅
spiral knot
#

I think this is ok. It's never added to the scene tree, though, so it's never added to the scene the player would be in.

#

There may be some risk if the script you're doing this in is attached to a node that is in the tree, but the way you have it, no, I don't see an inherent risk.

#

This sort of thing could eat up resources if you're doing it often or with large scenes, however.

timid raft
#

I just found this out recently that there's actually a built-in way to peek into a packed scene
https://docs.godotengine.org/en/stable/classes/class_scenestate.html

trail flax
#

I set up the following code to do some testing:

#
        print(object_resource.scene.get_state().get_node_name(i))```
#

And for each object it scans it's returning different numbers of nodes (which it shouldn't since all of my objects have the same node set up and only the settings change)

#

It's not returning every node in the scenes. For example: it's reading the CollisionShape2D nodes fine, but the Node2Ds or the NavigationObstacle2D nodes are not being counted

#

Not sure if I'm missing something... 🤔

#

All I really want to do is access the info in the parent scene node though, and even that I'm not 100% sure how I would do that. Looking through the docs, it doesn't seem to have a way of searching the nodes by name.

#

That why I was trying to read all the nodes here and then search them, but that's when I noticed not every node is getting returned back for some reason.

timid raft
#

PackedScenes also have a _bundled property which seems to contain all kinds of info. would be interesting to see in your case if it shows the same kinds of discrepencies

trail flax
#

Actually the scenes in question do not have other scenes inside, just nodes. However, they are inherited scenes;

#

I have a base_object scene, and I create "New Inherited Scenes" from that base object for all the other objects (table, chair, cabinet, etc.)

#

So they should all be the same minus the sprites, collider sizes, things like that

#

No clue why the node count would differ between them

#

Looking at the bundle stuff now...

timid raft
#

i searched github i couldnt find any issues relating to SceneState. i think its just not commonly used. the way of peeking into the scene that you are using in the first post was the only one recommended to me, too. so either this SceneState thing just isnt well-known or it has some undocumented issues...

trail flax
timid raft
#

i really dont wanna do a deep-dive into the source code, maybe i open a github issue and let someone else figure that out. if im able to reproduce these descrepencies

trail flax
#

I'll look some more into the bundled stuff, and otherwise I may just stick with wehat I got unless it becoems a problem, thanks for the help!

trail flax
#

After working a bit more with the _bundled property I'm not sure how to make it work for what I'm trying to do. I've only been able to peek at the names and some values but not really able to read those values. I could be doing something wrong, but yeah I may just stick with the method I've been using for now.