Packed scene created have null variables

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

My problem is as follows:

  1. I create enemies using an abstract enemy class and instancing it
  2. I read files from a “user://whatever” that has .tres files in it
  3. I have an initiating function in the abstract enemy scene that attaches the .tres file into the variables of the enemy
  4. I pack this instanced scene with the .tres file into a new scene
  5. I save that scene somewhere
  6. I create an .instance() of that packed scene,but the variables are null

Im doing this method because I want to create .tres files and instantly add new enemies,and also load them on the loading screen so there are no freezes during gameplay,but this doesn’t seem to be working.

Anyone with a similar problem?

:bust_in_silhouette: Reply From: Lopy

Make sure to export the variables that need to be saved.
Also, the variable initialized on _ready() need to wait for the Node to be added to the tree.

The .tres file has some instructions on how to make the enemy perform certain attacks,and add animations to them again from “user://”

Basically it instructions to create raycasts with certain parameters,and add them on a node, and add animation files with functions.

The other variables (such as hp/speed/etc) work fine,but this part doesn’t

I feel like whatever the scene is,if you pack it,it should remain the same and be “saved” as a scene/node to be instanced of,and not require you to export every variable,otherwise it seems somewhat counter-intuitive to what its purpose it. I do not know enough about the engine to understand if this is doable,but right now I don’t see any other reason to use packed scenes.

Zaxrem | 2021-01-01 17:34