- Home /
Rule Tile "GameObject" duplicating in build version
Hi all!
We're currently developing a Rogue-like 2.5 Doom-like game and we ran into some issues with the GameObject associated with Rule Tile.
We currently use the Rule Tile feature mixed with Tilemap to be able to easily draw new rooms that will be randomly placed in a dungeon-like pattern (think something like Binding of Isaac) whenever the player start said dungeon. This allows us to have all of our terrain objects and enemies in a Tile Palette, and easily draw whatever we want the player to experience as a challenge. This works great, as long as the game is running in the Editor.
When the game is Build, the GameObject are duplicated and all placed at the same (0,0,0) coordinate of the room. I've done some testing, and it seems to only happen for rooms that aren't already placed in the scene, which in our case is basically all the rooms (we instantiate the layout of the dungeon when the scene is loaded).
Here's some screenshots to get a better idea.
Here you can see 4 explosive barrels in the editor version of the room
Here you can see the same 4 barrels plus 4 duplicated ones that are stack on top of each other as they all tried to spawn at the same place in the build version of the room
Has anyone ever encountered something like this, or used the Rule Tile like that? I've done some testing, but I'm not sure where to go from here to solve this.
Thanks!
Do you have the rooms as Prefabs? Then instantiate that prefab and put it in place in the world? Any DontDestroyOnLoad objects, they might cause the creation of duplicate?
If you can, I suggest that you debug with brake points when the barrels Instantiate, or in Awake(). Make a Debug.Log() if you are on a mobile device.
But it could be anything else, since it doesn't happen editor. Do you have other objects you Instantiate that also show this?
The rooms are prefabs variants, all a variation of the same template room. No DontDestroyOnLoad except for Game/Music Manager and Player. This behaviour only happens for GameObject that are placed via the Rule Tile.
For the debugging, I'm not sure where I'd need to place the Debug.Log() since the actual instantiation of the GameObject Rule Tile is not done by any of my scripts. I've tried to pin point where this is happening in the Tiles code, but it didn't make complete sense to me. Also, side note, but how would one go about having debugging logs for a build game? Is there a specific place where the Debug.Log() are being recorded or do I need to set that myself?
On Windows it's simple, it's placed here Application.persistentDataPath + "/Player.log"
On Android this may work https://answers.unity.com/questions/1368808/how-to-see-debuglog-when-using-android.html
I have no further ides.
Answer by TavroxGames · May 16 at 11:07 PM
@Adamnation We have the same problem! We've been working on this bug for a few days now, very infuriating.
It is indeed very frustrating. We've tried to used the Tile Palette with GameObject instead of RuleTiles, but that removes all the nice features that allowed us to create rooms quickly. I really hope someone has a solution for this.
Since it seems like we are not going to get an answer, may I ask what have you guys tested so far to debug the issue?
We looked into the openly available rule tile scripts and nothing has led us to believe that the issue is coming from those scripts. We think that the issue might come from the instantiation of a 3D asset in the game world where it starts by instantiating the rule tile itself which is refering to a 3D asset and then it instantiates the 3D asset it references in its rule. That being said, we still can't find where the instantiation of these objects is located.
Although I don't like the next "solution", a greedy bandage-solution would be to have a method which get an array of everything at the position 0,0,0 of the scene via an overlap sphere or something and delete everything there except what is supposed to be at that position.
@TavroxGames I did find a work around that works for me. Basically, I place all the rooms that can be placed at random in my scene at a position out of the play area and a scale of 0. Once the scene starts, I randomly select my rooms, change their scale back to 1 and place them at the position of my previously calculated layout. Since I'm not instantiating the room, but instead moving it, I don't run into the duplicate gameObject issue. Let me know if this helps you out.
Answer by Erzats · May 16 at 04:34 PM
I would also be interested in an aswer, if anyone has one to share. I have the same issue.
Answer by theboxfriend · May 26 at 01:20 AM
I encountered the same issue and reported it as a bug to Unity. They were able to reproduce it and have added it to the issue tracker
A pretty hacky workaround that I've been using is checking the local position of the object, if it is at 0,0 it will destroy itself on Awake
This is exactly the behaviour I've been seeing.
I did find a work around that works for me tho. Basically, I place all the rooms that can be placed at random in my scene at a position out of the play area and a scale of 0. Once the scene starts, I randomly select my rooms, change their scale back to 1 and place them at the position of my previously calculated layout. Since I'm not instantiating the room, but instead moving it, I don't run into the duplicate gameObject issue. This seems to be working well for me and it even reduced the loading time of my scene. I'm now working on trying to make this even more optimal, got a couple of ideas I want to try out.
Your answer
Follow this Question
Related Questions
NullReferenceException on GameObjectInspector Editor Error 6 Answers
HELP!!!! The project can't be built. 1 Answer
How to fix bugs that only appear in the build? 0 Answers
Distribute terrain in zones 3 Answers
Build does behave different to editor 2 Answers