Community Forum
ANVEL Licensing Options

Parent vehicle ID of sensor

  • What is the easiest way to retrieve the ID of vehicle a sensor is attached to? The only way I've found involves calling GetParent() on the sensor's world object and then checking this parent's ID against world object IDs associated with all the vehicles. It seems like there has to be an easier way.

  • Good morning,
    Unfortunately the currently solution is not that much nicer, but it avoids having to search through the vehicle listing. The following code sample should work with sensors parented by the vehicle, or any vehicle subobject:

    #include "Vehicles/ODEVehicleObject.h"
    Vehicles::Vehicle* GetVehicleParent( World::Object* pWorldObject)
    auto* pParent = pWorldObject->GetParent();
    if ( !pParent )
        return nullptr;
    Vehicles::Vehicle* pVehicle = nullptr;
    ID parentID = pParent->GetComplexID();
    if ( GetDataType( parentID ) == Types::VehicleObject )
        auto pVehObj = static_cast<Vehicles::ODEVehicleObject*>( pParent );
        return pVehObj->GetOwner();
    else if ( GetDataType( parentID ) == Types::Vehicle )
        return Vehicles::Manager::GetSingleton().GetVehicle( parentID );
    return nullptr;
    //Usage from a sensor:
    auto pVehicle = GetVehicleParent(m_pWorldObject);

    The ANVEL Team