Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Long click on a plane => -[SCNNode changeMaterial]: unrecognized selector sent to instance #11

Open
Tasmagic opened this issue Sep 13, 2017 · 6 comments

Comments

@Tasmagic
Copy link

Tasmagic commented Sep 13, 2017

Hi,

I want to change the material of a plane. When I perform a long click on a plane, I got the following error:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SCNNode changeMaterial]: unrecognized selector sent to instance

On:

[((Plane *)parentNode) changeMaterial];

Any idea?

Thanks.

@tblanchard
Copy link

tblanchard commented Sep 15, 2017

Here's my workaround.

@interface SCNNode (Damn)
- (void)changeMaterial;
@end

@implementation SCNNode (Damn)
- (void)changeMaterial
{
    NSLog(@"changeMaterial sent to instance of %@",[self class]);
}
@end

@Tasmagic
Copy link
Author

I don't understand your workaround. May you elaborate ? Thanks !

@tblanchard
Copy link

Some instance of SCNNode is being sent the message changeMaterial that does not implement changeMaterial. Only the subclass Cube implements changeMaterial but the code sending the message isn't checking that the node it is sending changeMaterial is a Cube (or better - respondsToSelector:@selector(changeMaterial)).

So I added a category to SCNNode called changeMaterial that simply logs the message. It is overridden by the method in Cube. So now it is no longer an "error" to send changeMaterial to any SCNNode.

@Tasmagic
Copy link
Author

The problem is that with your solution the user has to click several times on the plane in order to be able to change its material. He has to click until the correct instance (Plane) is returned. This is not satisfying. I don't understand why the plane is not detected reliably when I click on it.

@tblanchard
Copy link

tblanchard commented Sep 19, 2017 via email

@FA65
Copy link

FA65 commented Oct 20, 2017

If it's not a Cube, check if it's a Plane then call changeMaterial

.......
if ([parentNode isKindOfClass:[Cube class]]) {
[((Cube *)parentNode) changeMaterial];
} else if ([parentNode isKindOfClass:[Plane class]]) {
[((Plane *)parentNode) changeMaterial];
}

I think the hit detection problem is that before hitting a Plane it can hit a feature point

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

No branches or pull requests

3 participants