Page 1 of 1

Bad Cast on Two Different Footbot Controllers

Posted: Tue Nov 10, 2020 9:41 am
by dtzl1999
I have some issue with dynamic cast for the loop function that I have created. Here is a part pertaining to the dynamic cast:

Code: Select all

CFootBotEntity& footBot = *any_cast<CFootBotEntity*>(it->second); CFootBotMobile& controller = dynamic_cast<CFootBotMobile&>(footBot.GetControllableEntity().GetController());
Besides that, I have deduced the issue behind the std::bad_cast error and able to reproduce it. The fault lies in the fact that I used two different footbot controllers within my xml file. Hence, the only way of fixing it is using only one of the controllers at a time but the setup that I am planning requires those two controllers to work.

I am wondering if there is any suggestion to solve this issue?

Re: Bad Cast on Two Different Footbot Controllers

Posted: Tue Nov 10, 2020 9:54 am
by pincy
Instead of casting to reference, cast to pointer and check whether the pointer is null or not.