Hello everyone,
I’ve been having this little (big) problem that I can’t solve or find the problem…
I have a script in the main camera that spawns a new cube in a random position in the scene, and adds a script called Heartbeat to it, that only has two methods: Start() and Update(), that logs with Debug.Log() the instanceId.
It starts logging the instanceId, as it’s logged in the Update() method, as expected.
However, if I spawn two cubes, the 1st one will stop logging the instanceId, and the 2nd one starts to log it.
Is there something I am doing wrong?
Here’s the code I am using for the instantiation:
public void createNewHeartbeat()
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.AddComponent<Heartbeat>();
cube.transform.position = new Vector3(Random.Range(-50, 50), Random.Range(-50, 50), Random.Range(-50, 50));
heartbeatsList.Add(cube.GetComponent<Heartbeat>());
}
Many thanks
Show us the heartbeat script also please. Are you sure they have stopped logging also and you don’t just have it set to collapse so it just stacks on each other?
Post the Heartbeat.cs code.
Alright, here’s the heartbeat code:
using System;
using System.Collections.Generic;
using UnityEngine;
public class Heartbeat : MonoBehaviour {
private cubesManager cManager;
public static Vector3 position;
// Use this for initialization
void Start () {
cManager = Camera.main.GetComponent<cubesManager>();
}
// Update is called once per frame
void Update () {
Debug.Log(this.GetInstanceID());
}
}
I’m not seeing anything odd. So I would say make sure you’re not just seeing collapse on and the number is incrementing. Also since update only works when the gameobject is active/script enabled, try turning off one gameobject and then the other to see if you still get print outs.
Are you sure there is literally nothing getting logged on that cube? Add some more info to the debug.log like the gameobject name to be sure.
Also, make sure you don’t have collapse toggled on in the Console.