0
\$\begingroup\$

In my map class I have an algorithm that is generating and merging box colliders together. These belong to the layer "Ground".

After that, in some places on my map I'm generating some new cubes on-the-fly, and some of these cubes I don't want to generate at all. So, I'm doing a raycast to determine if they should be added or not.

I'm doing these raycasts to check if the position they should be generated at have free space to the left and right. For both rays I'm checking if they hit a collider beloning to the layer "Ground".

But I don't get a hit at all!

I've tried to create two cubes in the editor and assign them to the layer "Ground". If I run the game then I get a hit between these two cubes. But I will never get a hit checking against my generated colliders.

I do this logic in the Start-method, is there any certain method in the life cycle when I can start to use my generated box colliders?

\$\endgroup\$
  • \$\begingroup\$ You want to make sure that Ground is being finished before starting to generate the additional cubes, is that correct? \$\endgroup\$ – Nikaas Jul 1 '16 at 10:49
  • \$\begingroup\$ -1 It's too unclear what you are asking. \$\endgroup\$ – S. Tarık Çetin Jul 28 '16 at 16:00
  • \$\begingroup\$ It would help to see a screenshot of the situation, and a snippet of code where you're doing the raycasting. It's easy to get false negatives from raycasts accidentally, but we won't know whether that's the issue until we can see exactly what you're doing. \$\endgroup\$ – DMGregory Aug 1 '16 at 14:06
1
\$\begingroup\$

Assuming you're trying to coordinate the Start() method of various scripts, you can ensure they execute in the order you want by going into the menu at Edit > Project Settings > Script Execution Order.

Just make sure your box collider script is running before the raycast script and you should be good to go!

From Unity's official documentation:

Script execution order menu

Scripts can be added to the inspector using the Plus “+” button and dragged to change their relative order. Note that it is possible to drag a script either above or below the Default Time bar; those above will execute ahead of the default time while those below will execute after. The ordering of scripts in the dialog from top to bottom determines their execution order. All scripts not in the dialog execute in the default time slot in arbitrary order.

The numbers shown for each script are the values the scripts are actually ordered by. When a script is dragged to a new position, the number for the script is automatically changed accordingly. When a number is changed, either manually or automatically, it changes the meta file for that script. For this reason it’s best if as few of the numbers as possible change when the order is changed. This is why, when possible, only the script that is dragged has its number changed, rather than assigning new numbers to all the scripts.

\$\endgroup\$
0
\$\begingroup\$

I had the same problem with a character collider; it used to miss collisions with objects. I found out that it was caused by a bug that has not been fixed, as of Unity 5.5.


The fix was simple. I added a capsule collider, and continuously checked for collision using OnTriggerStay().

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.