#Spawning Primitives under a same gameobject

1 messages · Page 1 of 1 (latest)

shrewd panther
#
            if (prefabInstance == null)
            {
                prefabInstance = ParentBundle.Base.LoadAsset<GameObject>(PrefabName);
                if (prefabInstance == null)
                {
                    return false;
                }
            }

            Object = UnityEngine.Object.Instantiate(prefabInstance, Position, Quaternion.Euler(Rotation));
            Object.hideFlags = HideFlags.DontUnloadUnusedAsset;

            Object.AddComponent<MeshFilter>();
            PrimitiveObjectToy primitive = Object.AddComponent<PrimitiveObjectToy>();
            primitive.PrimitiveType = PrimitiveType.Cube;
            primitive.NetworkPrimitiveFlags = PrimitiveFlags.None;

The pack is "Prefab GameObject => Primitives"

Before i just spawned the prefab and worked i tried adding to the gameobject of the prefab directly the PrimitiveObjectToy but doesn't work

white terrace
#

Uhhhh

#

What?

#

Use the PrimitiveObjectToy.Create(...) to spawn primitive game objects

#

@shrewd panther

shrewd panther
#

even tho for some reason it doesn't work outside of commands lol

#

if i do the command normaly it works for spawning my maps but in code it doesn't

white terrace
#

If your spawning custom maps/models, spawn them after OnWaitingForPlayers event fired

#

Or later

shrewd panther
white terrace
#

Should work too then

shrewd panther
#

but still nothing

white terrace
#

Check if the code actually runs

#

(print something)

shrewd panther
white terrace
#

If yes, get the position of the gameobject and check if it matches where it should be

shrewd panther
#

it exist on the server

#

not on the client

#

Because i have a spawnpoint system and it actually works fine

shrewd panther
#

so could it be that

#

because the command is runned by me

white terrace
#

Not related

#

You sure you have the networkSpawn to true?

shrewd panther
#

Command

white terrace
shrewd panther
shrewd panther
#

but with api they don't

white terrace
#

What is PrefabInfo?

#

and bundle?

#

That is not ours

shrewd panther
#

this is a plugin im doing

white terrace
#

Well then... you gotta show me what you do in the method?

shrewd panther
#

The problem still is that before 14.1 everything worked

#
        public bool Spawn(Vector3 position, Vector3 rotation, Vector3 scale, GameObject prefabInstance = null, int dimensionId = -1)
        {
            // Despawn object if its already spawned.
            if (IsSpawned)
                DeSpawn();

            if (prefabInstance == null)
            {
                prefabInstance = ParentBundle.Base.LoadAsset<GameObject>(PrefabName);
                if (prefabInstance == null)
                {
                    // Something went very wrong.
                    return false;
                }
            }
            
            DimensionId = dimensionId;

            // Cache for reloading purposes.
            Position = position;
            Rotation = rotation;
            Scale = scale;

            Object = UnityEngine.Object.Instantiate(prefabInstance, Position, Quaternion.Euler(Rotation));
            Object.hideFlags = HideFlags.DontUnloadUnusedAsset;
            Object.transform.localScale = Scale;

            Spawnables = Object.GetComponentsInChildren<SpawnableInfo>();

            foreach (SpawnableInfo spawnable in Spawnables)
            {
                if (spawnable.Type == SpawnableType.Primitive)
                {
                    Optimize()
                }

                spawnable.Spawn(this);
            }

            ParentBundle.PrefabSpawned?.Invoke(this);
            return true;
        }
#
//this is spawn
PrimitiveObjectToy primitiveInstance = PrimitiveObject.CreateNewInstance(primitive.transform);
                    primitiveInstance.NetworkScale = primitive.Scale;
                    primitiveInstance.NetworkPosition = primitive.Position;
                    primitiveInstance.NetworkRotation = Quaternion.Euler(primitive.Rotation);
                    info.SpawnedBy.SubObjects.Add(primitiveInstance.gameObject);

                    // Setup intial values.

                    primitiveInstance.NetworkIsStatic = !primitive.IsAnimated;

                    primitiveInstance.NetworkScale = primitiveInstance.transform.CalculateGlobalScale();
                    primitiveInstance.NetworkMaterialColor = primitive.Color;
                    primitiveInstance.NetworkPrimitiveType = primitive.PrimitiveType.ToPrimitiveType();

                    PrimitiveFlags constructFlags = PrimitiveFlags.None.Set(PrimitiveFlags.Visible, primitive.IsVisible).Set(PrimitiveFlags.Collidable, primitive.IsCollidable);
                    primitiveInstance.NetworkPrimitiveFlags = constructFlags;
white terrace
#

I suggest try to use LabAPI method for spawning

#

See if that works

shrewd panther
#

I do the same exact method

#

as labapi so it doesn't make any sense

shrewd panther
#

@white terrace i found out that now every primitives needs to be near the map else they break or don't spawn for client, and btw culling doesn't work for lights on surface they get bugged im reporting this in the official way

white terrace
#

Ofc

#

That has been in game since..

#

primitives been added

#

Also wdym about the lights?

#

@shrewd panther

shrewd panther
shrewd panther
meager oracle
white terrace
#

Oh wait the zones has been a bit shrinked together

#

And room code rewritten

#

so that may be why

meager oracle
#

from what it seems like (for surface at least) attempting to spawn any primitive above 100m of y.300 will just not spawn for the client

white terrace
shrewd panther
shrewd panther
white terrace
meager oracle
#

prims could spawn pretty much anywhere before 14.1 (going up to y.1500 in my testing) but now anything above about y.360 just wont show on the client

white terrace
#

I believe you

#

Well, sorry for any troubles caused but I doubt this will be changed back

#

You can suggest something to compensate for this on LabAPI's github

meager oracle
#

quite a major issue for our tourneys and projects

#

alright

shrewd panther
meager oracle
#

oh yeah right

white terrace
#

Not as of right now yea..

meager oracle
#

spawning doors could increase the relative positioning

white terrace
#

we would have to add some kind of culling-exception bounds

#

or something

#

I haven't seen the culling code soooo I dont know how exactly it works

shrewd panther
#

at this point im re-suggesting it like i did many time

meager oracle
atomic horizon
#

they don't solve the issue of culling unfortunately

#

just make sure the doors are at the root of the scene, otherwise there will be horrible amounts of desync

shrewd panther
#

but the doors outside don't work

atomic horizon
#

how did you spawn doors?

shrewd panther
atomic horizon
#

i can't help with that unfortunately
just use the PrefabCache, get a door, position it and NetworkServer.Spawn
pretty much any BreakableDoor will work

#

right

#

um