How to add a Tilemap to a prefab? - unity3d

I have a Bomb prefab that gets dinamically added to the center of a 2D tile on keypress via a BombSpawner script. When the bomb explodes, I want it to affect multiple tiles in my Ground tilemap.
The explosion is inside the BombController script which is part of my Bomb prefab. I tried accessing the tilemap by adding it manually to the prefab:
public Tilemap tilemap;
But it doesn't work. I can only drag and drop the tilemap to the Bomb when it's in the scene, not to the prefab.
Is there a way to access the Ground tilemap inside the BombController script?

So, This is what is normal in unity when you are working with prefabs. You can only assign components/scripts anywhere in prefab if that component/script is a part of the prefab itself.
If component/script is in your scene hierarchy but not in the prefab. In your case, it was Tilemap object. which was in your scene hierarchy but was not the part of your prefab. Even if you edit the prefab directly in the scene view(Don't get confused with prefab editor which looks as same as scene view). and save the prefab the BombController.tilemap will always be null(None). Something Like

have you tried importing this library from unity
using UnityEngine.Tilemaps;
and then do that variable
public Tilemap tilemap;
enter image description here

Related

Cannot move object with NavMeshAgent in Unity

I can't move uploaded models in the Unity with NavMeshAgent. They just walk while standing still. And whenever I start the game it gets it's "y" position as something different than it should be. This might be the problem but there's nothing that changes the position.
To use NavMeshAgent you need to add Rigidbody component to your uploaded model and also bake your NavMesh like terrain, obstacles and so on.

Unity, I can't make a Prefab out of a Tilemap

When I try to create a prefab this happens:
I select the tilemap
I create the prefab by dragging it down
I open the prefab and nothing works
There is no way to edit it through its tile palette editor and it has only a tile.
I see this also when I try to instantiate a tilemap (both from a prefab or an already ingame gameobject)
How can I fix?

Unity2D: Prefab not working with animator

I have a prefab that is instantiate in using my spawning script. I also have a game over panel that slide down (this is done by animation) once the player dies. The problem I'm having is that the needs to be game over panel attach to the prefab in the inspector window for the game over panel to work. This image explains everything. Please help
in Unity you can't assign scene objects to prefabs because prefabs must be usable within all your scenes, so if a scene object was assignable to a prefab then the prefab couldn't be used in another scene.

Unity2D - Level with invisible collisions

In my Unity2D project I want that to load a level as a sprite from my resources. The game is a top down view. I then want to add invisible collision boxes where the walls in the level-image are.
How would I do that?
I have attached a box collider to my player and now? Creating an empty game object with another box collider doesnt work.
See #Savlon comment, you need rigidbody with your collider component as well for empty objects. And they will provide blocking of player object if you player object also have collider and rigidbody. Don't mark your colliders as trigger and ensure they are on the same layers.

Unity FBX goes through every object

I'm learning how to use mecanim and followed a tutorial using the Raw Mocap animation set from the unity store. But the default rig would walk through cubes and fall through the plane. I've added colliders to the cube and plane but it still wouldn't work. Any guidance will be appreciated.
your character should have colliders too and if it has a rigidbody component attached to it set IsTrigger=false and it it has player controller attached to it it will only collide if the other object has player controller too