jacksondunstan / UnityNativeScripting

Unity Scripting in C++
https://jacksondunstan.com/articles/3938
MIT License
1.33k stars 135 forks source link

How to new GameObject(constructor not correct) #42

Closed sekkit closed 5 years ago

sekkit commented 5 years ago

new GameObject() But no gameobject is created in scene. Based on Blog articles, there is a GameObjectNew func can do that? so the question is, how to create GameObject(or any other Plugin generated object) correctly?

jacksondunstan commented 5 years ago

You'll need to expose that constructor to C++ in order to use it. Here's how the JSON looks:

{
    "Name": "UnityEngine.GameObject",
    "Constructors": [
        {
            "ParamTypes": []
        }
    ]
}

After generating the bindings, you can create the GameObject in C++ like so:

GameObject go;
sekkit commented 5 years ago

Can't I just GameObject *go = new GameObject()? why create it in stack? I noticed there is no pointer in your cpp plugin bindings