EsProgram / InkPainter

Texture-Paint on Unity.
https://esprogram.github.io/InkPainterDocument/
MIT License
1.24k stars 169 forks source link

Creating an InkCanvas on runtime. #74

Open DKarampistis opened 2 years ago

DKarampistis commented 2 years ago

I am using CSG (Constructive Solid Geometry) to create a mesh on runtime. The mesh is given a MeshCollider component and collisions work fine. I tried to add an InkCanvas component but it was causing an exception. NullReferenceException: Object reference not set to an instance of an object Es.InkPainter.InkCanvas.InitPropertyID () (at Assets/InkPainter/Script/Core/InkCanvas.cs:323) Es.InkPainter.InkCanvas.Awake () (at Assets/InkPainter/Script/Core/InkCanvas.cs:265) UnityEngine.GameObject:AddComponent() ObstacleGeneratorV2:Start() (at Assets/Scripts/ObstacleGeneratorV2.cs:26)

The InkCanvas is added after the MeshCollider. Here is a part of the code:

        Model result = CSG.Subtract(bigGameObject, smallGameObject);
        var composite = new GameObject();
        composite.tag = "Obstacle";
        composite.AddComponent<MeshFilter>().sharedMesh = result.mesh;
        composite.AddComponent<MeshCollider>().sharedMesh = result.mesh;
        composite.AddComponent<MeshRenderer>().sharedMaterials = result.materials.ToArray();
        composite.AddComponent<InkCanvas>();
        composite.transform.parent = this.transform; 

Am I adding the component wrong or it's not possible for it to be added on runtime.

hassannibg commented 2 months ago

Hey! did you find any solution for this problem