I have save load problem, Saving transform in 3D world SOLVED

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

When loading the scene, the position of nodes are not loaded because main scene has default object properties

 get_tree().reload_current_scene() 

when I reload with this or load and queu.free() my previous scene;

all positions although loaded, not works. How can I reload or load the scene and have my load.tres file work?

get_node("Player").transform.origin = Vector3(48.672, 128.565, -31.473)
var yu : Resource = load("res://Scenes/Player/Player.tscn")

How are you saving the positions? Are you storing it as a variable then assigning it or saving it to a JSON or config file?

Magso | 2020-03-11 12:29

I save them in .tres file and then read them:
Vector3(a, b, c)

Okan Ozdemir | 2020-03-11 12:34



	var mm3 = save_game_values.data2["%s" % node.name].values()[0]
	get_node(node.get_path()).transform.origin = Vector3(mm3[0], mm3[1], mm3[2])

Okan Ozdemir | 2020-03-11 12:50

.tres files are used for resources like materials, skyboxes etc. As far as I’m aware there isn’t a way to save types to a tres file, your code is getting a value from a dictionary and storing it in an array. The floats in a Vector3 are a struct, not an array so instead of mm3[0] it will be mm3.x

Magso | 2020-03-11 20:31

Thanks that will nicely do

Okan Ozdemir | 2020-03-12 10:33

Can you reply this as an answer so I can mark it as resolved?

Okan Ozdemir | 2020-04-19 13:34

Sure. I’ve just clarified it a little more as well.

Magso | 2020-04-19 14:20

:bust_in_silhouette: Reply From: Magso

.tres files are used for resources like materials, skyboxes etc. As far as I’m aware there isn’t a way to save types to a tres file unless it’s a custom resource.
Your code is getting a value from a dictionary and storing it in an array. The floats in a Vector3 are a struct, not an array so instead of mm3[0] it will be mm3.x

Basically it’s Vector3(struct{float x, y, z}) not Vector3([1, 2, 3])

User Magso - Godot Engine - Q&A Thanks Magso You have helped me so much!

Okan Ozdemir | 2020-04-20 13:20