Start a new topic

I am trying to move a plane from a custom shader with a click on an UI Button. Nothing happens though

 Hi everyone,

I am trying to develop an AR app which uses a custom shader in order to do a cross section of a gameobject in Unity. 

The custom shader uses a plane to do the cross sectioning of the object material

it is attached to.

My objective is to move the plane along the Z axis so that it performs a cross-section on the gameobject.

These are the properties that it uses for the plane


_PlaneNormal("PlaneNormal",Vector) = (0,0,1,0)
_PlanePosition("PlanePosition",Vector) = (0,0,1,1)

The object I am trying to modify has 3 materials with the second one using the custom shader.

This is the code for the script

public class Halb : MonoBehaviour
    MeshRenderer meshRenderer;

       public void Halbsicht()
        // Get the mesh renderer of the object
        meshRenderer = GetComponent<MeshRenderer>();
        meshRenderer.materials[1].SetVector("_PlanePosition", new Vector4(0, 0, 0, 1));    

The script is attached to a gameobject that appears as soon as the image target is recognised.


The Button's OnClick() function calls the function Halbsicht() which gets the meshrenderer of the second material and then should set a new vector that would move the plane.


I have tried to manually move the plane on runtime and it works. However when I click on the button on runtime nothing happens.

Do you know what could be wrong?

The Wikitude version I am using is Wikitude SDK 9.5. The Unity version is: 2019.4.10f1

Thanks in advance


1 Comment

Hi Sammy,
that's very hard to tell from this standpoint... Are you sure that the event is being triggered during runtime? Could it be that the value is overwritten right afterwards by another script?

Kind regards,

Login or Signup to post a comment