How to send Variant data as input to a function?

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

I’m trying to optimize using servers, and am trying to use the function PhysicsServer.shape_set_data ( RID shape, Variant data ). I have created a SphereShape in the PhysicsServer, and now I want to set its radius. The only way I can figure how to do so is through the .shape_set_data function, but I don’t understand what to pass as Variant data. I have the RID of the shape, so that’s of no concern.

In Python I would use a keyword parameter as such: myfunction( radius=2.0 ), but that doesn’t seem supported in Godot.

:bust_in_silhouette: Reply From: Ertain

I think the Variant part requires the choice of a certain shape. So you have to pass one of the enumerated ShapeTypes. More information can be found in the documentation.

One can create shapes in the PhysicsServer by for example shape = PhysicsServer.shape_create(PhysicsServer.SHAPE_SPHERE). But after that I don’t understand how to change their radius.

Supposedly the PhysicsServer knows that shape is of type SHAPE_SPHERE after creation, so what remains is to somehow set its radius. If that should be done through the shape_set_data( shape, <other input> ), then what remains is to understand how to set its radius through the <other input>.

Another method would be to define a shape in the following way:

shape = SphereShape.new()
shape.radius = 5.0

I’ve created bodies and visualinstances and set their shapes to SphereShape.new() which seems to work. But I’m not sure it’s the proper way to work with the servers.

toblin | 2020-04-24 09:10

I would think that, after you created the shape with shape_create(), it would return an object with the data. However, it only returns the RID. My only guess is that, after the shape is assigned to an area or a body, its properties can be set through the the area or body. I’m also looking at the shape_get_data() function, which returns the data for the shape.

Ertain | 2020-04-24 17:32

I’ve proceeded to use SphereShape.new() for the shapes, whose radius can easily be changed by .radius= value. I’m not sure this is the proper way of doing it however, since it seems to take long to set the radius on the shapes later.

toblin | 2020-04-28 13:19