#pls help with parenting Schematic objects to SpawnableCullingParent

1 messages · Page 1 of 1 (latest)

sand geyser
#

Greetings! I'm trying to optimize MER schematics by moving them into a SpawnableCullingParent to enable culling and setting toys to static. However, I’ve run into a serious synchronization issue.

When I change the parent of an AdminToyBase and set NetworkIsStatic = true inside the SchematicSpawned event, the objects immediately become invisible for players who are already on the server. It seems like Mirror fails to sync the new hierarchy and static state because the initial spawn packet has already been processed by the clients.

???
wet geyser
#

you should be able to just set the transform parent, no need to pass false and then reposition it

sand geyser
wet geyser
#

You'd create a Bounds struct and call Encapsulate with each child's MeshFilter's bounds

carmine sierra
#

i just made a system similar

#

but uses both bounds and thing and its entirely client

#

so

#

it heavily relies on meow even if i post it here

#

and btw this system doesn't work

#

because if you don't watch them you can go through the floor

sand geyser
#

take a look dm please @wet geyser

wet geyser
#

I'm on phone rn, I can get back to it later

snow dagger
carmine sierra
#

let me check to rewrite that so it doesn't use method you guys never know lol

#
        public Bounds CalculateBounds()
        {
            IReadOnlyList<SpawnableInfo> children = GetComponentsInChildren<SpawnableInfo>();
            bool initialized = false;
            Bounds result = default;

            foreach (SpawnableInfo child in children)
            {
                if (child == this)
                    continue;

                Bounds childBounds = child switch
                {
                    MeowEditorPrimitive primitive => primitive.GetBoundingBox(),
                    MeowEditorLight light => light.GetBoundingBox(),
                    MeowEditorCapybara capybara => capybara.GetBoundingBox(),
                    MeowEditorCulling nested => nested.CalculateBounds(),
                    _ => default
                };

                if (childBounds.size == Vector3.zero)
                {
                    if (!Extensions.TryGetColliderBounds(child, out childBounds)
                        && !Extensions.TryGetRendererBounds(child, out childBounds)
                        && !Extensions.TryGetMeshFilterBounds(child, out childBounds))
                    {
#if !EDITOR
                        Vector3 fallbackCenter = child.Position;
                        Vector3 fallbackSize = child.Scale;
#else
                        Transform childTransform = child.transform;
                        Vector3 fallbackCenter = childTransform.position;
                        Vector3 fallbackSize = childTransform.lossyScale;
#endif

                        if (fallbackSize == Vector3.zero)
                            fallbackSize = Vector3.one;

                        childBounds = new Bounds(fallbackCenter, fallbackSize);
                    }
                }

                if (!initialized)
                {
                    result = childBounds;
                    initialized = true;
                }
                else
                {
                    result.Encapsulate(childBounds);
                }
            }

            if (!initialized)
            {
                if (!Extensions.TryGetColliderBounds(this, out result)
                    && !Extensions.TryGetRendererBounds(this, out result)
                    && !Extensions.TryGetMeshFilterBounds(this, out result))
                {
                    Vector3 size = transform.lossyScale;
                    if (size == Vector3.zero)
                        size = Vector3.one;

                    result = new Bounds(transform.position, size);
                }

                initialized = true;
            }

            if (initialized && BoundsPadding != Vector3.zero)
            {
                Vector3 extents = result.extents + BoundsPadding;
                result.extents = new Vector3(
                    Mathf.Max(extents.x, 0f),
                    Mathf.Max(extents.y, 0f),
                    Mathf.Max(extents.z, 0f)
                );
            }

            return result;
        }
#

The other bound box should be relative easy to calculate

snow dagger
#

cuz i see u used #if editor

wet geyser
#

you can't attach a debugger

carmine sierra
wet geyser
#

unless if you wanna debug assembly

carmine sierra
#

that code is just for my editor

#

i made a custom editor thats why

#

#if editor

means its just for the editor to visualize it

#

or some stuff that its not needed in game

sand geyser
wet geyser
#

yeah so you'll need to make them not static for a frame

#

or respawn the schematic

snow dagger
#

I think he already added a delay

snow dagger
sand geyser
sand geyser
snow dagger
sand geyser
snow dagger
#

wdym

sand geyser
#

Anyway, I'm going to record a video right now

snow dagger
#

Ill try it in a moment

sand geyser
wet geyser
#

i have no idea

#

might be a MER issue

sand geyser
#

It looks like the client is trying to get the coordinates and is getting the wrong static objects

snow dagger
#

idk it works for me

#
 foreach (AdminToyBase adminToy in schematic.AdminToyBases)
            {
                adminToy.NetworkIsStatic = true;
            }
sand geyser
snow dagger
#

yes

#

schematic.transform.SetParent(parent.Transform, true);
maybe try with this

sand geyser
#

CullableParent or Static?

snow dagger
#

cullable -> parent -> static

sand geyser
#

schematic.AdminToyBases works

#

@snow dagger thx so much

snow dagger
#

but be carefull that the schematic could disappear for no reason since its not in center of the bouds