GetUserData

This command can be used to return a user data value set with the Object::SetUserData command.

Syntax

Returns

The user data value set by the end user. If no user data value has been set for this Object, the returned value is NULL.

This function is not available in Lua.

Example

#include "Leadwerks.h"

using namespace Leadwerks;

Model* model = NULL;
class EntityData
{
public:
int health;
};

int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
DirectionalLight::Create()->SetRotation(35,45,0);

//Create a model
model = Model::Box();
model->SetPosition(0,0,3);

//Create our own custom object
EntityData* entitydata = new EntityData;
entitydata->health = 100;

//Set the model user data
model->SetUserData(entitydata);


while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;

Leadwerks::Time::Update();
world->Update();
world->Render();

//Retrieve our custom object
EntityData* entitydata = (EntityData*)model->GetUserData();

//Display the health value
Draw::SetBlendMode(Blend::Alpha);
Draw::Text(String(entitydata->health),0,0);
Draw::SetBlendMode(Blend::Solid);

context->Sync();
}
return 0;
}