Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by nopogo · Feb 09, 2018 at 11:04 AM · texturetilemaptile

What is the correct way to add gameobjects to tiles

Right now I based my custom tile on the unity ruletile example from github where I set the gameobject of the tile in the gettiledata class. This correctly places an instance of the prefab as a child of the tilemap in the right possition. It works right??


 public override void GetTileData(Vector3Int position, ITilemap tileMap, ref TileData tileData){
             tileData.sprite = m_DefaultSprite;
             tileData.colliderType = m_DefaultColliderType;
             tileData.flags = TileFlags.LockTransform;
             tileData.transform = Matrix4x4.identity;
             tileData.gameObject = tilePrefab;
 }



However whenever I start and stop the scene I get the following errors:


Can't destroy Transform component of 'ItemPrefab(Clone)'. If you want to destroy the game object, please call 'Destroy' on the game object instead. Destroying the transform component is not allowed.


And when I try to build the project the build fails with the message:


Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.


Anybody here knows the correct ways to set custom gameobjects (with scripts) on a tile (either spawned by code with SetTile() or painted in editor)?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nopogo · Feb 21, 2018 at 03:38 PM

Updating to the latest version of unity resolved my errors

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by rolographic · Nov 20, 2018 at 09:53 PM

It was hard to find but you can fix that behavior by unchecking the Tilemap component on the Layer1 inside the palette.

Screenshot

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FDT · Feb 18, 2018 at 11:23 AM

You have to instantiate the gameobject first.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nopogo · Feb 19, 2018 at 11:48 AM 0
Share

I've tried doing this, the result is an instantiated object at origin, then a copied version of this object at the correct location. So either that is the way to go and im doing something wrong, or this is and im missing something (or the linked gameobject in the tilesystem was never intended for this purpose)

avatar image nopogo · Feb 21, 2018 at 12:23 PM 0
Share

I'm even more confused now, : according to Unity's own documentation im setting the gameobject correctly

avatar image
0

Answer by Salleyyyyy · Apr 03, 2020 at 07:52 PM

Hi @nopogo , Here is my solution, if any questions are there, please ask:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.Tilemaps;
 using UnityEngine;
 
 /**
     Klasse eines default Tile, auf dem weitere Gegenstände abgebildet werden
 **/
 
 public class DefaultTile : Tile
 {
 
 
     //Sprite für den Boden
     private Sprite default_Sprite; 
     private static GameObject object_test;
     private static bool c = false;
 
     
     /**
     public override void RefreshTile(Vector3Int position, ITilemap tilemap)
     {
         Debug.Log("Refresh Methode");
         tilemap.RefreshTile(position);
     }
     **/
     
     
     public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go){
         Destroy(object_test);
         return true;
     }
     
     
 
     /**
         Methodenaufruf, um Informationen zum Rendern des Tiles zu erhalten, wie z.B. das Sprite des Tiles
     **/
     public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
     {
         Debug.Log("Methode GetTile");
         this.default_Sprite = Resources.Load<Sprite>("Floor");
         tileData.sprite = this.default_Sprite;
 
         if(!c){
             object_test = GameObject.CreatePrimitive(PrimitiveType.Cube);
             c = true;
         }
         
         tileData.gameObject = object_test;
     }
 
 
 }
 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Salleyyyyy · Apr 03, 2020 at 07:55 PM 0
Share

It is important to say that i am using Unity version 2019.3.7f1, as since this version the cloned gameObject is placed in the middle of the tile.

avatar image Salleyyyyy · Apr 03, 2020 at 08:13 PM 0
Share

PS: This is a solution without a prefab. If you have a prefab, you should not instantiate it, use e.g. a public attribute and drag and drop the prefab. I think there shouldn't be a problem as far as you don't instantiate it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to check if a position has a type of tile 1 Answer

Can't Destroy Transform Component Error after exiting Play mode 2 Answers

How can I Remove one tile from tilemap 1 Answer

Problem with 2D tiles from a tilemap appearing blurry in game 0 Answers

When I flip my sprite it goes out of the tilemaps foreground 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges