Editor Export Object (PackedScene) Array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LaCocoRoco

Hi, i couldn’t find a satisfying answer and after reading the Q&A i will jump directly into the question:

Code snippet:

const Tool : PackedScene = preload("res://scene/tool_0.tscn")

When i move the file “tool_0.tscn” via “Move To…” the code path will not be updated.

To fix this i used the next snippet (Drag & Drop the “tool_0.tscn” in the editor) so i can move the “tool_0.tscn” file around as i want.

export (PackedScene) var Tool : PackedScene = null

At last i made an export Array, defined every element of it as an object in the editor and moved some Scene files via Drag & Drop into it.

export (Array) var Tool : Array = []

godot

  1. Is there a way to define an Array as “PoolObjectArray”,
    “PackedSceneArray” or something like that?
  2. I can’t use “preload” in “export”, does this impact performance?
  3. I read through many topics like best practice, code architecture, dynamic resources etc., but could not find a good answer. Is there a reason not to handle it like that?
export (Array, PackedScene) var my_array

Is that what you looking for?

Surtarso | 2021-02-24 00:49

Yes, that was what i searched for!
I will not change the “Best answer” because i think it has some good additional information.
But if someone has the same question regarding the Array, this is the correct solution!

LaCocoRoco | 2021-03-03 06:49

:bust_in_silhouette: Reply From: Lopy
  1. No, you can not specify the type of what the Array holds. There are a few Pool…Array, but they act differently than regular Arrays.
  2. load and preload are just as slow as one another. The only performance difference, is that if you call load during gameplay and the Resource has not already been loaded, the player will notice a stutter. To avoid that, try loading the Resource a first time outside of gameplay, like when the Scene is loaded.
  3. Do not get too fixated with “best practices” and try to evaluate pros and cons yourself. I see two issues with this approach:
  • Renaming the exported array will wipe the data contained inside them project-wide.
  • You need to be careful to always make a new Array when filling one for a different object, as the default Array when exporting will be shared by default (: Array = null would fix this).

Instead of exporting an Array directly, if you want to save the content of the Array to disk in a separate file, you could make a custom Resource (set a class_name and export an Array).

You should avoid having variable names begin with an uppercase, this is usually reserved for the name of classes.

This answered all of my questions!
Also very good additional information.
I appreciate every improvment i can get.
Probably i should stop to overthinking things.
Hopfully this was an acceptable question, there will probably be more in the future.

Thank you and i wish you a very nice day!

LaCocoRoco | 2021-02-10 01:12