gamecreator Posted August 8, 2016 Share Posted August 8, 2016 Does anyone have any idea why the following code would return NULL? Material* material = player.model->GetMaterial(); The entity does have a material and loads fine in the program. What else could cause the code to return NULL? Quote Link to comment Share on other sites More sharing options...
Josh Posted August 8, 2016 Share Posted August 8, 2016 The entity has no material, but the model surface(s) each have a material. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
gamecreator Posted August 8, 2016 Author Share Posted August 8, 2016 Thanks. I think this did come up before. It is a little confusing though since the example on this page does it a lot like I did. http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetmaterial-r127'>http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetmaterial-r127 Material* material = entity->GetMaterial(); Also, GetMaterial is one of the functions on the Entity page. http://www.leadwerks.com/werkspace/page/api-reference/_/entity/ Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 8, 2016 Author Share Posted August 8, 2016 I tried Material* material = player.model->GetSurface(0)->GetMaterial(); And it crashed the program. The console said "Error: Surface index out of range." I tried GetSurface(1) and same thing. Then I thought maybe I need to get a child first, which seems reasonable, even though the GetSurface example on the Barbarian model doesn't do that. Material* material = player.model->GetChild(1)->GetSurface(0)->GetMaterial(); which got me Error 12 error C2227: left of '->GetMaterial' must point to class/struct/union/generic type Error 11 error C2039: 'GetSurface' : is not a member of 'Leadwerks::Entity' Thoughts? Quote Link to comment Share on other sites More sharing options...
martyj Posted August 8, 2016 Share Posted August 8, 2016 Use surfaces vector. player.model->surfaces[0]->GetMaterial() ? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 8, 2016 Author Share Posted August 8, 2016 Thank for the suggestion but that crashed the program. The example from the surface documentation does Surface* surface = model->GetSurface(0); but if the GetMaterial example is incorrect then maybe this is too? Quote Link to comment Share on other sites More sharing options...
Josh Posted August 8, 2016 Share Posted August 8, 2016 GetChild() returns an entity: Material* material = ((Model*)player.model->GetChild(1))->GetSurface(0)->GetMaterial(); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
gamecreator Posted August 8, 2016 Author Share Posted August 8, 2016 Thanks! That worked. It's still crashing when I try to implement it in the SetPixels example but I'll take a moment to try to figure that one out. 1 Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted August 9, 2016 Share Posted August 9, 2016 Thanks! That worked. It's still crashing when I try to implement it in the SetPixels example but I'll take a moment to try to figure that one out. I noticed when implementing a system today that even on some surfaces GetMaterial() returns null.... So I guess some surfaces simply don't have materials on them, just check and make sure 'Surface::GetMaterial() != NULL'. I noticed this in a similar situation, when I was relying on the fact that Surface::GetMaterial() never returned null, when in fact it does in many cases so I had some crashing til I did a check to make sure the returned value isn't NULL, now I'm getting the expected behavior. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted August 9, 2016 Author Share Posted August 9, 2016 Yeah, some of this is still a mystery. I wonder what the difference between the barbarian model is that you don't need to get its child in the example versus mine. But I don't have time to get too distracted. Gotta work on some simple animations! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.