instance does not have an associated physics representation

M

maelstrom

Guest
Getting an unusual error when I changed an object from using the GUI physics settings to manually assigning the physics settings...

############################################################################################
ERROR in
action number 1
of Create Event
for object obj_obstacle:

The instance does not have an associated physics representation
at gml_Object_obj_obstacle_CreateEvent_1 (line 9) - physics_set_density(fixture,0);
#####################################################################

previously, when I created the object with the GUI physics settings, it threw no errors

incidentally, if I don't place the object in a room, there's no error, but throws the error when I place it in the room

creation code is as follows...

var fixture = physics_fixture_create();
physics_fixture_set_box_shape(fixture, sprite_width/2, sprite_height/2);
physics_set_density(fixture,0);
physics_set_restitution(fixture,0.2);
physics_fixture_set_friction(fixture, 0.5);
my_fix = physics_fixture_bind(fixture, id);
physics_fixture_delete(fixture);

Additional Notes
the room uses 3D and like I said, I've had no errors up til now. It's only when I assigned the physics manually to the object the error appeared. I've tried changing the room's instance order so its at the top, bottom, etc...

The reason why I wanted to assign the physics manually, is that I need a mechanism to turn on/off physical collisions for this object, arbitrarily. I assumed I'd use physics_fixture_set_sensor(fixture, state), where 'fixture' is the 'my_fix' pointer I have in my code above. Not sure this works but was willing to give it a try - if anyone has a better suggestion I'd be happy to hear it.
 
M

maelstrom

Guest
did you checked the box that said that your room is physics room?
yes, like I said, everything was working previously - the error only began when I created the fixture manually, so to speak?
 
M

maelstrom

Guest
UPDATE:

commented out the set_density, friction and restitution and the code runs without errors and displays correctly

if anyone can elaborate further, I'd appreciate it

Also, the method to turn ON/OFF physical collisions for an instance using physics_fixture_set_sensor doesn't work (for me) - this would appear only intended to work when initially setting up the physics settings manually for the object, during the create event. Once the fixture has been bound to the instance, the fixture would be manually deleted. I ended up setting the following to achieve this:

phy_active = false
 
Last edited by a moderator:
M

maelstrom

Guest
https://docs.yoyogames.com/source/d...ics/fixtures/physics_fixture_set_density.html

I believe the density has to be above 0 to function at all. I dont know ive never used this feature so dont take my word for it.
I think you're mistaken here - from the official YoYo docs on Physics...

  • Kinematic - There will be certain instances in a physics based game which you want to move around but do not wish to be acted on by forces such as gravity, nor forces incurred by collisions with dynamic objects (think of moving platforms in a platform game, for example). For such objects simply setting the density of the fixture to 0 will mean that the physics will assume that the object is intended to be static and it will not react at all to anything. However, checking this box will make a static object kinematic and although it will be unaffected by collisions and gravity, it can still be moved around or rotated using the appropriate variables.
 

Jezla

Member
The functions you're using to set density and restitution are incorrect. When you define a fixture, you use physics_fixture_set_density etc.

physics_set_density is for changing a bound fixture. See the difference? That's what's causing you to get that error.

In the same way, physics_fixture_set_sensor is for use when defining a fixture, not changing one that's already bound. To turn collisions on or off, you'll want to use collisions groups, then remove the fixture and bind a new fixture assigned to a different group.

setting phy_active is not a good solution, in my opinion, because it turns the entire physics simulation off for that instance.

Edit 2: @Quinnlan Varcoe is correct, to use physics_set_density on a bound fixture, the fixture has to be defined with a density greater than 0. See this thread here.
 
Last edited:
Top