You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to serialize and deserialize a single object, the only object that moves in the scene, when I do it goes for one frame to the positions it had when it was serialized and in the next frame it goes back as if nothing happen.
If I serialize and deserialize the whole space it works, but it's too much data, I only need the data from the moving object.
To Reproduce
Steps to reproduce the behavior:
Make the following scene:
RigidBody2D
CollisionShape2D (It's a circle)
Let the circle start falling and save the state (say at -100 y), after some time more time restore to the previous state (say the ball at this point is at - 800 y), the circle will flash for one frame to the position where you saved the state (-100 y) and one frame later it will continue falling like nothing happen (the circle will be at - 800 y) .
This is the code I use to serialize/deserialize:`
extends Node
@onready var _context : Context = get_tree().get_root().find_child("Context", true, false)
class SerializationData:
var state : PackedByteArray
var rid : RID
func _init(state: PackedByteArray, rid: RID):
self.state = state
self.rid = rid
var states : Array[SerializationData] = []
func save_state():
get_tree().paused = true
states.clear()
states.append_array(get_state(_context.main_ball))
func get_state(node : BallSimulation) -> Array[SerializationData]:
var states : Array[SerializationData] = []
var shape_rid = node.get_rid()
states.append(SerializationData.new(
RapierPhysicsServer2D.export_binary(shape_rid), shape_rid
))
for owner_id in node.get_shape_owners():
for owner_shape_id in node.shape_owner_get_shape_count(owner_id):
var inner_shape_rid = node.shape_owner_get_shape(owner_id, owner_shape_id).get_rid()
states.append(SerializationData.new(
RapierPhysicsServer2D.export_binary(inner_shape_rid),
inner_shape_rid
))
return states
func restore_state(states : Array[SerializationData]):
get_tree().paused = true
print ("states = ", states.size())
for state in states:
RapierPhysicsServer2D.import_binary(state.rid, state.state)
func _on_restore_pressed() -> void:
restore_state(states)
func _on_save_pressed() -> void:
save_state()
Expected behavior
The ball should start at - 100 y after restoring instead of continuing at - 800 y.
Environment:
OS: macOS
Version: Tried both 0.8.8 and 0.8.10
Godot Version: v4.x
Type: slow fully deterministic.
Example project(zip)
Let me know if I need to make an example project. Maybe I'm just missing something to deserialize.
Notes
Also, the documentation about deserialization doesn't match the code, in the documentation the code to deserialize is:
RapierPhysicsServer2D.space_import_json(space_rid, exported_json) var body_json = RapierPhysicsServer2D.collision_object_import_json(body_rid, exported_json)
Describe the bug
I'm trying to serialize and deserialize a single object, the only object that moves in the scene, when I do it goes for one frame to the positions it had when it was serialized and in the next frame it goes back as if nothing happen.
If I serialize and deserialize the whole space it works, but it's too much data, I only need the data from the moving object.
To Reproduce
Steps to reproduce the behavior:
Make the following scene:
Let the circle start falling and save the state (say at -100 y), after some time more time restore to the previous state (say the ball at this point is at - 800 y), the circle will flash for one frame to the position where you saved the state (-100 y) and one frame later it will continue falling like nothing happen (the circle will be at - 800 y) .
This is the code I use to serialize/deserialize:`
Expected behavior
The ball should start at - 100 y after restoring instead of continuing at - 800 y.
Environment:
Example project(zip)
Let me know if I need to make an example project. Maybe I'm just missing something to deserialize.
Notes
Also, the documentation about deserialization doesn't match the code, in the documentation the code to deserialize is:
RapierPhysicsServer2D.space_import_json(space_rid, exported_json)
var body_json = RapierPhysicsServer2D.collision_object_import_json(body_rid, exported_json)
But the code only has the method:
RapierPhysicsServer2D.import_binary(state.rid, state.state)
There are other methods in the documentation that doesn't exists in the code.
The text was updated successfully, but these errors were encountered: