Advertisement Jump to content
Sign in to follow this  

Construct Angelscript object in memory

This topic is 1083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I would like to construct a user defined Angelscript type (defined in a script file) in a pre-allocated memory buffer, using the type name and a parameter list. For example:

// In Angelscript
class SomeClass
    SomeClass(int a, int b)

    int value;

Then the type name and some construction parameters are passed in from some other text file. Something like this:


"SomeClass", "(2, 5)"


Then I will allocate memory according to size of SomeClass

asUINT uiSize = pkEngine->GetObjectTypeByName("SomeClass")->GetSize();
// allocate some memory

Am I able to call the constructor "SomeClass(2, 5)" in that memory location? Do I need to know the parameter types?


Edit: GetObjectTypeByName("SomeClass") is not working actually; SomeClass does not seem to be recognised as an object type. If I iterate over all types, it is only picking up types I have registered through the c++ api.

Edited by Wolfbrother

Share this post

Link to post
Share on other sites

I figured out that I need to find the type within the module I loaded the scripts into:

asUINT uiSize = pkEngine->GetModule("Module")->GetObjectTypeByName("SomeClass")->GetSize();

I found a couple of functions that might allow me to create a default constructed object, and then copy it to my buffer. But this does not let me call a non-default constructor.

void* pvObject = pkEngine->CreateScriptObject(type);
pkEngine->AssignScriptObject(pvMemory, pvObject, type);
pkEngine->ReleaseScriptObject(pvObject, type);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!