godotengine / godotengine/godot
`var_to_bytes_with_objects` embeds Resources and can break global scripts
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
4.4 and earlier
### System information
W10
### Issue description
If you use `var_to_bytes_with_objects`, Resources will be serialized as any other object. This means they will get embedded in the data and re-instantiated when you do `bytes_to_var_with_objects`. In worst case it can break global scripts if you accidentally serialize a script.
This affects Objects and all properties, i.e. Resource properties will get embedded. There is a special exception for `script` property that makes it stored as path, but if you export a custom Script variable, the script will get embedded.
This is inconsistent with `var_to_str`, which stores Resources as path when possible.
### Steps to reproduce
Recipe for breaking script:
1.
```GDScript
class_name MyResource extends Resource
```
2.
```GDScript
extends Node
@export var script2: Script = MyResource
func _ready():
bytes_to_var_with_objects(var_to_bytes_with_objects(self))
```
3.
```
Parser Error: Class "MyResource" hides a global script class.
```
### Minimal reproduction project (MRP)
N/A
Contributor guide
Research direction
Start by reproducing the reported case with var_to_bytes_with_objects and bytes_to_var_with_objects, then compare the behavior with var_to_str for Resource and Script properties. Done means Resource values are stored as paths when possible and a custom Script variable no longer embeds or re-instantiates a script that can break global script classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100