Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the building object, wen it hit with other, i want to call some method inside it.

    NSLog(@"printTest method work correctly");

in my ContactListener i trying to call it so:

#import "ContactListener.h"
#import "Building.h"
void ContactListener::BeginContact(b2Contact* contact)
    b2Body* bodyA = contact->GetFixtureA()->GetBody();
    b2Body* bodyB = contact->GetFixtureB()->GetBody();

    Building *buildA = (Building *)bodyA->GetUserData();
    Building *buildB = (Building *)bodyB->GetUserData();
    if (buildB.tag == 1) {
        NSLog(@"tag == 1");
    if (buildA.tag == 2) {
        NSLog(@"tag == 2");
        [buildA printTest];

NSLog(@"tag == 2"); work correctly, but [buildA printTest]; get error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite printTest]: unrecognized selector sent to instance 0x18595f0'

Obviously I'm referring to the wrong object. How i can get different method and property in contacted objects from contactlistener class? Thanks.

share|improve this question

I found a solution on my own.

When I create the body, I forgot to set the UserData correctly.


Adding the line above (in solved the problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.