Physic and Start or Update

I generate a random dungeon at startup and there I apply a check for the possibility of placing a room if there is no other method already there using the Physics.OverlapBox or Physics.CheckBox method, but this does not work, I also tried placing it in the first update and this also does not work, and only after The 2nd frame is checked.

Tell me why this is and how you can initially use the physics test?

private void Awake(){
   CreateDangeon(); // create and check collision
   }
 
private void Start(){
   CreateDangeon(); // create and check collision
   }

private void FixedUpdate(){
   if(boolStartPhysic){
      boolStartPhysic = false;
      CreateDangeon(); // create and check collision
      }
   }

all 3 methods do not work, only after the 2nd frame it starts working…

private byte boolStartPhysic = 2;

private void FixedUpdate(){
   if(boolStartPhysic != 0){
      if(boolStartPhysic == 2){
        boolStartPhysic = 1;
        }
    else{
        boolStartPhysic = 0;
        CreateDungeon();
        }
    }
  }

this is the only option that works

If you change physics stuff, do you need to wait for the internal physics update to run before you can do stuff with it?

Like if you changed some stuff in Start or FixedUpdate or whatever, do you need to wait for yield WaitForFixedUpdate before you can do stuff with it.

It’s weird that is not working on the FixedUpdate

Try

private IEnumerator Start()
{
yield return new WaitForFixedUpdate();
CreateDangeon():
}

After placing your objects at startup you should call Physics.SyncTransforms() and then you’ll be able to do physics checks on them within the same frame.

2 Likes

waiting for the next frame is not an option, this is “live construction” of the labyrinth, that is, each next step is physically checked.

but this is a bad option, as I understand it, I ended up doing it differently, a dictionary of coordinates and filling them in the right direction, and then I combined several of them as floors and the result was a multi-level 3D dungeon (labyrinth) that is built in a random order and has several layers .

In general, I managed without physics…