#Generator Prefab

1 messages · Page 1 of 1 (latest)

autumn grove
#

When I spawn a generator prefab at a certain position, it stands at position zero on the client until it re-enters the server, and on the server the position is valid, here is the code

        private static GameObject SpawnGenerator(Vector3 position, Quaternion rotation)
        {
            GameObject prefab = NetworkClient.prefabs.Values.FirstOrDefault(g => g.name == "GeneratorStructure");

            if (prefab == null)
                throw new NullReferenceException("Generator prefab not found");

            GameObject copy = UnityEngine.Object.Instantiate(prefab);
            
            copy.transform.position = position;
            copy.transform.rotation = rotation;
            
            NetworkServer.Spawn(copy);

            return copy;
        }
stoic skiff
#

btw you can Instantiate(prefab, position, rotation)

void merlin
#

get the StructurePositionSync component and call its Start method before spawning the object

#

also, pass the position and rotation to instantiate

#

instead of setting them after

autumn grove
void merlin
#

np

void merlin
#

since

#

idk

stoic skiff
#

i didnt have to do this when i made a generator

#

13.5 tho

#

so ig 14.0 or 14.1 changed it

void merlin
#

yeah

#

gotta love using/setting networked properties in start and start only

stoic skiff
void merlin
#

check that class

stoic skiff
#

not opening rider rn

void merlin