/
/
/ "BRO TIGER"2017-11-05 17:07:45
C++ / C#
/ "BRO TIGER", 2017-11-05 17:07:45

How not to find through the tag objects whose name is "Preview Scene"?

Good day Toaster! I ran into an interesting problem in my opinion, I don’t know if it’s a Bug or a Feature ... I have MeshCombiner, which in turn combines the rendering meshes into one and adds this result to the Calider and to the Physics script. I find it like this:
1) Create an array of Cases GameObject[] hulls;-> Fill the array by searching for a specific tag

GameObject.FindGameObjectsWithTag("/*Название Тэга*/");

2) Next, I look for MeshFilters through this array: To do this, I create an array of Filters MeshFilter[] filters;-> I fill it with a long array of Cases -> Then, through the for loop, I look for MeshFilters... filters = new MeshFilter[hulls.Length];
for (int i = 0; i < hulls.Length; ++i)
            filters[i] = hulls[i].GetComponent<MeshFilter>();

3) Next, I just combine... (I think it's not worth describing this process because it's not about combining)
As a result, I sometimes encounter the fact that I find "Invisible" objects that do not exist!!!
Screenshot of the Inspector:
59ff1b27b4e2c255467230.png

Only restarting the Editor helps, but sometimes it comes back...
Unity version: 2017.2.03f (Recent, but this was also present in the previous one)
Have you encountered this? And who could solve this problem?
Thanks in advance!
Additional materials to the topic:
Script MeshCombiner.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshCombiner : MonoBehaviour
{
    public GameObject[] hulls;
    public MeshFilter[] filters;

    public void CombineMeshes()
    {
        Quaternion oldRot = transform.rotation;
        Vector3 oldPos = transform.position;

        transform.rotation = Quaternion.identity;
        transform.position = Vector3.zero;

        hulls = GameObject.FindGameObjectsWithTag("Hull");
        filters = new MeshFilter[hulls.Length];

        for (int i = 0; i < hulls.Length; ++i)
            filters[i] = hulls[i].GetComponent<MeshFilter>();

        Debug.Log(name + "Комбинируем...");

        Mesh finalMesh = new Mesh();

        CombineInstance[] combiners = new CombineInstance[filters.Length];

        for(int i = 0; i < filters.Length; i++)
        {
            if (filters[i].transform == transform)
                continue;

            combiners[i].subMeshIndex = 0;
            combiners[i].mesh = filters[i].sharedMesh;
            combiners[i].transform = filters[i].transform.localToWorldMatrix;
        }

        finalMesh.CombineMeshes(combiners);
        finalMesh.name = "PlayerShipMesh";

        GetComponent<MeshFilter>().sharedMesh = finalMesh;
        GetComponent<FloatingGameEntityFlat>().buoyancyMesh = finalMesh;
        GetComponent<MeshCollider>().sharedMesh = finalMesh;

        transform.rotation = oldRot;
        transform.position = oldPos;
    }
}
EDIT: The topic is still open, because the same "Bug" surfaced 2-3 days later...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2017-11-05
@BasmanovDaniil

Most likely, you find service objects of the editor. If they are hidden in the hierarchy, you can check Object.hideFlags and weed out those with the HideInHierarchy flag set .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question