Log in or register to post comments

HowToTurnOffMeshTemporarily

March 23, 2012 - 9:38pm #1

I need to reduce the number of draw calls in my Unity project when playing under iOS.

Unity 3.4 QCAR 1.5 xCode 4.2

I have tried a multitude of approaches to turn off the mesh renderer, deactivate the game object etc.

These methods can successfully turn off the game object and/or its components. However they will not turn back on again. Or they work in the Unity editor but fail under iOS.

I also find a distinct difference in behaviour in the Unity editor and when running under iOS using these methods.

Is there a specific method for turning off and on the mesh renderer component that will reliably work on iOS?

Or activate/deactivate game objects that are within the tracker hierarchy?

HowToTurnOffMeshTemporarily

January 11, 2019 - 1:55am #10

Is it possible to disable the mirror modifier temporarily, so that I can model my creature with different spikes locations without being mirrored, and then enable it again? It would save me lot of time modelling the rest of his body that will be mirrored

Re: HowToTurnOffMeshTemporarily

March 25, 2012 - 8:27pm #9

Oops! Just realised my error. Shouldn't try and call GameObject from inside a render components method.

Re: HowToTurnOffMeshTemporarily

March 25, 2012 - 8:22pm #8

I have added the raycast layer change to the DefaultTrackableEventHandler as quoted below.
It doesn't solve my other problem which is that even though I can't see the object being tracked to the target. I can click on the image being tracked and the raycast still triggers.

I imagine there is something incorrect in my code?

Quote:

private void OnTrackingFound ()
{
Renderer[] rendererComponents = GetComponentsInChildren ();

// Enable rendering:
foreach (Renderer component in rendererComponents) {
component.enabled = true;
// Enable raycast
gameObject.layer = 0;
}

Debug.Log ("Trackable " + mTrackableBehaviour.TrackableName + " found");
Debug.Log("Raycast " + mTrackableBehaviour.TrackableName + " enabled");
}

private void OnTrackingLost ()
{
Renderer[] rendererComponents = GetComponentsInChildren ();

// Disable rendering:
foreach (Renderer component in rendererComponents) {
component.enabled = false;
// Disable raycast
gameObject.layer = 2;
}

Debug.Log ("Trackable " + mTrackableBehaviour.TrackableName + " lost");
Debug.Log("Raycast " + mTrackableBehaviour.TrackableName + " disabled");
}

Re: HowToTurnOffMeshTemporarily

March 25, 2012 - 7:36pm #7

Thank you for posting that code snippet.

I will use that to turn on and off the raycast layer.
As well as the renderers.

Re: HowToTurnOffMeshTemporarily

March 25, 2012 - 6:26am #6

You're probably right. Whatever method they're using to select child objects for reactivation is missing the Renderer.

Here's how this is handled in the DefaultTrackableEventHandler script..

    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = true;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }

Re: HowToTurnOffMeshTemporarily

March 24, 2012 - 7:34pm #5

It looks like I have fixed the issue.

I can use Playmaker to Activate Game Object to deactivate the game object recursively thereby turning the entire hierarchy off On Awake.
Then use Activate Game Object to reactivate most of the hierarchy recursively combined with an Enable Property (Mesh Renderer) action which will enable the mesh renderer specifically because Activate alone doesn't achieve this.
Once the Enable Property (Mesh Renderer) boolean has been activated you need to use it again to turn off the render mesh property each time you use Activate to re-deactivate the game object. For any further activate/deactivate cycles.

Odd.

Could well be an issue with Playmaker because it recursively turns everything off correctly but misses the mesh renderer component recursively when reactivating.

Re: HowToTurnOffMeshTemporarily

March 24, 2012 - 6:26pm #4

Here is some sample code that doesn't work.
I attached it to a game object with a render component and it remains visible on play in the editor. The game object is in a target hierarchy.

using UnityEngine;
using System.Collections;

public class rendererOnOff : MonoBehaviour {

void Awake() {
renderer.enabled = false;
}

void renderOn ()
{
renderer.enabled = true;
}

}

Re: HowToTurnOffMeshTemporarily

March 24, 2012 - 6:04pm #3

In this situation it is better to turn off the renderer rather than use culling.

I am using Playmaker (Hutong Games) to run the code which will make sending the code a bit difficult.

It sounds like I will need to write a handler and call that from Playmaker.
I will give that a go.

What I find complicates the issue is that most of the methods I tried work in the editor but once installed on iPad they fail.

Re: HowToTurnOffMeshTemporarily

March 24, 2012 - 7:35am #2

You should be able to use the standard approach of enabling and disabling the Renderer.

Can you post some code that you're using to control rendering on these objects?

Also if you have a Pro license, you can use occlusion culling.

Log in or register to post comments