Load the position of an entity
You can load (read from the state fabric) the position of an entity using an integer data structure. These examples use the following function:
Note
You must provide Api::BuiltinTypeId::Vector3F32
to Api::LoadEntityIndexKey()
, as shown in the following examples.
Example using an array to represent the position
Result<void> GetEntityPosition(Api::Entity& entity, Transaction& transaction) { std::int8_t* dest = nullptr; WEAVERRUNTIME_TRY(Aws::WeaverRuntime::Api::LoadEntityIndexKey( transaction, entity, Api::BuiltinTypeIdToTypeId( Aws::WeaverRuntime::Api::BuiltinTypeId::Vector3F32), &dest)); std::array<float, 3> position = *reinterpret_cast<std::array<float, 3>*>(dest); }
Example using a struct to represent the position
struct Position {struct float x; float y; float z; }; Result<void> GetEntityPosition(Api::Entity& entity, Transaction& transaction) { std::int8_t* dest = nullptr; WEAVERRUNTIME_TRY(Aws::WeaverRuntime::Api::LoadEntityIndexKey( transaction, entity, Api::BuiltinTypeIdToTypeId( Aws::WeaverRuntime::Api::BuiltinTypeId::Vector3F32), &dest)); Position position = *reinterpret_cast<Position*>(dest); }