How to obtain a reference to the gameobject placed by a custom voxel

Modified on Wed, 07 Apr 2021 at 08:26 AM

Use the following code to get a reference to the instantiated gameobject:


GameObject voxelGameObject = env.GetVoxelGameObject(position);


An instantiated gameobject is a regular gameobject created by Voxel Play based on the custom voxel definition.


Notes:


1) If the custom voxel definition has GPU Instancing enabled, there's no gameobject in the scene (unless it's marked to be created explicitly in the voxel definition).


2) To change the material of this gameobject, just use GetComponentInChildren<Renderer>() on the returned gameobject and use the .material property to ensure you only modify a self copy of the material used by all instances of this same voxel definition in the scene.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article