Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision shapes overridden in inherited scenes are not used by physics, but display fine. #8103

Closed
Tracked by #4778
need12648430 opened this issue Mar 21, 2017 · 13 comments

Comments

@need12648430
Copy link

Operating system or device - Godot version:
Godot 2.1, built recently from Github's 2.1 branch.

Issue description:
Collision shapes overridden in derived nodes are not used by the physics. They are, however, displayed fine both in the editor and in game with the 'visible collision shapes' option enabled.

Further inspection confirms that the NodePath of the collision shape does point to the base scene's resource while the game is running.

The expected behaviour is of course that the scenes use their own collision shapes when overridden.

Steps to reproduce:
Create a scene with a KinematicBody2D root, and a CollisionShape2D helper node. In that node, create a CircleShape2D resource of radius 32. Save as A.tscn

Create an A.tscn inherited scene, B.tscn. In the inherited CollisionShape2D node, create a new CircleShape2D resource of radius 16. Save.

Create Main.tscnand instance both A and B. Turn on visible collision shapes. Both the editor and running game will show the expected collision shapes. But B will still reference A's collision shape, as you can test with any collision.

Link to minimal example project:
InheritedSceneResources.zip

Remember to turn on visible collision shapes when testing this project. That sprite following the mouse cursor will turn red when over a shape, I figured it'd make the issue easier to see.

If you take a peek at the console, I've printed the shape resources' NodePaths. You'll notice that the NodePath of both shapes are identical.

@eon-s
Copy link
Contributor

eon-s commented Mar 22, 2017

Duplicate of related to #5798

@need12648430
Copy link
Author

There is a collision shape on the inherited scene, it's just the wrong one. Not a duplicate issue. Check the example.

@eon-s
Copy link
Contributor

eon-s commented Mar 22, 2017

@need12648430 right, changed to related, I think all are the same issue with shape resources, like if the inherited uses the base list of shapes/resources when added to the tree.

@need12648430
Copy link
Author

I thought so too, but I tried changing the id of the subresource by hand to something distinct in the inherited scene, to no avail. I need to look more into it - it might be related, but not necessarily.

@eon-s
Copy link
Contributor

eon-s commented Mar 22, 2017

Looking at the resource ID, both CollisionObjects have the same resource, while the CollisionShapes have different ones.

Base CS reference to the base shape while the other has a new one, that is why you see the correct shape drawn by the helper.

Add this to the for on the example script

print(child.get_shape(shape).get_rid().get_id())
print(child.get_child(0).get_shape().get_rid().get_id())

edit: forcing the CollisionShape to update the parent on ready with a script like this:

func _ready():
	get_parent().set_shape(0,get_shape())

Works in the editor, not sure if an exported on release project too (I don't know how helpers work there)

@reduz
Copy link
Member

reduz commented Mar 22, 2017 via email

@need12648430
Copy link
Author

Great information and brilliant find, thank you. Even if I can't fix the bug, just forcing the shape to update will save me a lot of refactoring in the meantime.

@need12648430
Copy link
Author

@reduz Any advice on patching this one for 2.1? I know you've got your hands full, more than willing to help if possible. :)

@eon-s
Copy link
Contributor

eon-s commented Mar 22, 2017

@need12648430 I don't know the origin of the problem, it could be the way instances are initialized and how shapes are added, CollisionShape nodes and tool mode is another bad combination, among other similar issues.

I hope @reduz find a way to solve all these cases with shapes (and others) on 3, even breaking apart the current shape system.

@kubecz3k
Copy link
Contributor

@need12648430 this one rather wont be patched for 2.1, this would break backward compatibility, you manage your shapes manually in 2.1 for example by using clear_shapes(); and add_shape on the area/body node. All issues related to collision shapes not beeing used by body share common case, which is the way how collision shapes are threaded by the engine, it was design decision not the bug. This should be resolved when #2314 and #5798 will be resolved. Leaving open for now, since it might be interesting in the future to test provided use-case/example.

@kubecz3k
Copy link
Contributor

kubecz3k commented Aug 2, 2017

I think this should be fixed now. Can you recheck?

@eon-s
Copy link
Contributor

eon-s commented Aug 2, 2017

@kubecz3k the issue seems to be solved on Godot 3 alpha.

@kubecz3k
Copy link
Contributor

kubecz3k commented Aug 3, 2017

@eon-s awesome, thanks for check :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants