- Home /
Help with scriptable tiles PLEASE HELP URGENT!!!
I think I coded my custom tiles wrong. When you load the scene from another scene, I receive the error message The referenced script on this Behaviour (Game Object '<null>') is missing!
So here is my script:
using UnityEngine;
using UnityEngine.Tilemaps;
namespace UnityEngine
{
[CreateAssetMenu]
public class CollisionTile : TileBase
{
public Sprite Sprite; //The sprite of tile in the palette
public GameObject ToSpawn; //The gameobject to spawn
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
// Assign variables
if (!Application.isPlaying) tileData.sprite = Sprite;
else tileData.sprite = null;
if (ToSpawn) {
ToSpawn.transform.position = position;
ToSpawn.transform.Translate(new Vector3(0.5f,0.5f,0.0f));
tileData.gameObject = ToSpawn;
}
}
public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
{
go.transform.position += Vector3.up * 0.5f + Vector3.right * 0.5f;
return true;
}
}
}
What's wrong with it? Here is the inspector for the tile:
i would guess the tiledata reference is lost when you load the scene
you need to carry the reference over into the next scene. i would make a game object and attach a sort of manager that stores references you want to keep using https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html and have any scripts that need those references to look towards that manager
Answer by AdamOliver · Jun 11, 2018 at 07:05 PM
The inspector shows that script is "None". You've probably renamed the script and this object has lost the reference to it. Just re-create this object and set it up again, should work
It doesn't let me, its greyed out and not interactive.
I basically did rename it. The problem was that the actual script was named BlockScript.cs
. So changing the name inside the script worked like a charm! ($$anonymous$$eaning I did rename it.) Thank you.
But yeah, I didn't even have to set everything up again. All I had to do was change the script, re-add it, and now my game is done!
Your answer
Follow this Question
Related Questions
How to Change the position of a tile to the player position? 0 Answers
How to make different Rule Tiles interact with each other? 0 Answers
Equivelant "set" method for "getInstantiatedObject"? 0 Answers
Efficient way of placing multi-tile sprites onto tilemap via script 0 Answers
Multiple Cars not working 1 Answer