Question by
Trosunion · Apr 21, 2021 at 09:42 AM ·
scripting probleminspector
Transform position overwritten by inspector value
Hi everyone,
I have 2 classes: World and Player. This is the world class, it has a reference to the player.
public class World : MonoBehaviour
{
public int seed;
public BiomeAttributes biome;
public Transform player;
public Vector3 spawnPosition;
public Material material;
public BlockType[] blockTypes;
public Chunk[,] chunks = new Chunk[VoxelData.WorldSizeInChunks, VoxelData.WorldSizeInChunks];
List<ChunkCoords> activeChunks = new List<ChunkCoords>();
List<ChunkCoords> chunksToCreate = new List<ChunkCoords>();
ChunkCoords playerChunkCoords;
ChunkCoords playerLastChunkCoords;
private bool isCreatingChunks;
void Start()
{
Random.InitState(seed);
spawnPosition = new Vector3((VoxelData.WorldSizeInChunks * VoxelData.ChunkWidth) / 2f, VoxelData.ChunkHeight - 50f, (VoxelData.WorldSizeInChunks * VoxelData.ChunkWidth) / 2f);
GenerateWorld();
playerLastChunkCoords = GetChunkCoordsFromPos(player.position);
}
}
On the start function, i calculate the spawn position of the player and set on the GenerateWorld() function.
void GenerateWorld()
{
for (int x = (VoxelData.WorldSizeInChunks / 2) - VoxelData.ViewDistanceInChunks; x < (VoxelData.WorldSizeInChunks / 2) + VoxelData.ViewDistanceInChunks; x++)
{
for (int z = (VoxelData.WorldSizeInChunks / 2) - VoxelData.ViewDistanceInChunks; z < (VoxelData.WorldSizeInChunks / 2) + VoxelData.ViewDistanceInChunks; z++)
{
chunks[x, z] = new Chunk(new ChunkCoords(x, z), this, true);
activeChunks.Add(new ChunkCoords(x, z));
}
}
player.position = spawnPosition;
}
However the value of the position of the transform component of the player, keeps getting overwritten bye the inspector value which is (0, 0, 0) so my player always spawns at this position, and not in the middle of the world.
Any suggestions.
Thank you in advance,
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613032619im_/https://answers.unity.com/themes/thub/images/avi.jpg)