godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.99k stars 19.51k forks source link

Rigidbody3D does not emit NOTIFICATION_TRANSFORM_CHANGED (2000) #83086

Open Carsillas opened 9 months ago

Carsillas commented 9 months ago

Godot version

v4.1.stable.mono.official [970459615]

System information

Godot v4.1.stable.mono - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 (NVIDIA; 31.0.15.3640) - AMD Ryzen 7 7700X 8-Core Processor (16 Threads)

Issue description

I have attached the following script in the attached reproduction, and you can see that the notification method is only triggered a single time at the beginning of execution, despite the cube falling into the void. I would expect transform notifications to be triggered whenever the position of the body changes, as is the case with CharacterBody3D.

Also note that despite my engine version (mono) this occurs when using gdscript as well, the reproduction project is written in gdscript.

extends RigidBody3D

# Called when the node enters the scene tree for the first time.
func _ready():
    set_notify_transform(true);

func _notification(what):
    if what == NOTIFICATION_TRANSFORM_CHANGED:
        print(what);

Steps to reproduce

Minimal reproduction project

BugReport.zip

AThousandShips commented 9 months ago

Can you test this with the latest version of 4.1? Here

Carsillas commented 9 months ago

Will do after work, in around ~4 hours

AThousandShips commented 9 months ago

Looking at the code I'm not sure this is supposed to work, though it isn't documented as far as I can see

RigidBody is different from the others in that it's controlled by physics and shouldn't be manipulated directly, it deactivates updates to the position being sent when writing back the physics updates

Carsillas commented 9 months ago

Why should it not work? The transform is being updated, regardless of what is updating it

AThousandShips commented 9 months ago

Yes but it blocks the notification, because it would create a cycle I think, because it updates the physi a engine

Carsillas commented 9 months ago

I don't see how that would be possible, does the engine listen to that notification? If it relies on it then why is it disabled by default?

AThousandShips commented 9 months ago

It turns it off when updating the state from the physics server, so that the notification only happens when the transformation is updated manually, as far as I know, you can look at the code and see

Carsillas commented 9 months ago

I believe you I'm just wondering if this is somehow not considered a bug. What's the point of having a notification for it if it doesn't actually work in the scenario that you aren't setting it yourself

AThousandShips commented 9 months ago

I mean the notification isn't specific to RigidBody3D? It's to Node3D, it is relevant to all Node3D derived classes, so it has many many uses outside of this, again unsure if this is a bug or not, I think it is a limitation, and the work involved in making it work safely with bodies affected by physics like this might be more complicated, compared to the usefulness of being able to detect when a RigidBody3D is affected by physics

Have you turned on set_notify_local_transform? I believe it works on its own as the editor uses it, and makes more sense since RigidBody3D is usually meant to not be tied to global transform as it is independent

Carsillas commented 9 months ago

Local transform does seem to work. That is acceptable for my use case, I still feel this is potentially a bug though. Will leave this open for now for you guys to decide. Even if the resolution is just to document this quirk