[SOLVED] Managed pointers to custom classes


Recommended Posts


Say we have a custom class called Foo, which has managed Unigine pointers to another custom class called Bar.
So, here is Foo's definition for now :

class Foo
  	Unigine::Ptr<Bar> m_bar;
  	Foo() = default;
  	void setBar(Unigine::Ptr<Bar> ptr){ m_bar = bar; }

Now, when I try to add this implementation to the Unigine interpreter, I use the following code :

Unigine::ExternClass<Foo>* fooClass = Unigine::MakeExternClass<Foo>();


fooClass->addFunction<Foo, void, Unigine::Ptr<Bar>>("setBar", &Foo::setBar);

Unigine::Interpreter::addExternClass("Foo", fooClass);

I get a compile error saying that 'release_ptr' is not a defined member of Foo. So, I defined 'static void release_ptr(Foo* p){ delete p; }' in the Foo class.

Now I get a "'type cast': cannot convert from 'void*' to 'Type' " in UnigineInterpreter.h.

Any ideas on how to solve this error?

Thanks in advance

Link to post

Hi Karim,

There is no Unigine::Ptr in UnigineScript. Also it's not clear how you exposed Bar class.

You can check all the possible ways of doing that in the following sample: <SDK>\source\samples\Api\Scripts\Classes.


How to submit a good bug report
FTP server for test scenes and user uploads:

Link to post

Hi silent,

Ok, I changed my managed class implementation according to the sample and now it works.

Thank you.

Link to post
  • silent changed the title to [SOLVED] Managed pointers to custom classes