Comments (8)
The ITilemap functions are callbacks from the Tilemap to the Tile to retrieve information from the Tile.
Instead, you could trigger this from the Tilemap itself by calling either:
- tilemap.RefreshTile (if you want to refresh specific Tiles at positions)
- tilemap.RefreshAllTiles (if you want to refresh all Tiles at any position)
from 2d-extras.
Thanks.
That works fine for standard Tiles, but does not work for RuleTile as RuleTile's RefreshTile function requires an ITilemap to use.
For now I'm using tilemap.RefreshAllTiles() but that's horribly inefficient for large Tilemaps. Do you have any suggestions for how to use RuleTile.RefreshTile()?
from 2d-extras.
Let me try to confirm what you would like to do:
- Update the Rules for a RuleTile (eg. changing the output Sprite of a Rule or adding new Rules)
- Have a Tilemap (or Tilemaps) with this RuleTile refresh all Tiles that are that RuleTile so that the updated Rules take effect
The RuleTile's RefreshTile function refreshes the RuleTile at the given position for the given Tilemap, so if the above is correct, that will not do what you want.
I guess the Tilemap would need a new function to do this which would be tilemap.RefreshTiles(Tilebase tile)?
from 2d-extras.
Thank you for spending time looking into this. It is much appreciated. I could see someone using both of the scenarios you mentioned above, however my use case is different.
I have a Tilemap on which only one type of Tile is placed and it's a RuleTile. The user is "digging" and whenever they dig, as long as they haven't previously dug there, a RuleTile is placed on the Tilemap at that location. So if I dig at location 0,0, it adds a RuleTile to the Tilemap. If I then dig at location 0,1, it adds a RuleTile. Since those two tiles are touching, and since there's a rule for those scenarios (e.g. there is a tile below me and nothing above or to the sides), both tiles need to update which Sprite is shown in order to reflect that they are placed next to each other. I hope that makes sense. I can make a gif to show you an example if that would help.
from 2d-extras.
You can try using tilemap.SetTile( position, tile ), eg. tilemap.SetTile(new Vector3Int(0, 0, 0), ruleTile); tilemap.SetTile(new Vector3Int(0, 1, 0), ruleTile); . The tilemap will automatically update the Sprites of the Tiles you have set.
from 2d-extras.
I have been setting the tiles as you outline and they show up with the default rule but never update to match the outlined rules unless I call tilemap.RefreshAllTiles() after setting the tile. After setting a RuleTile, I would like to individually call Refresh() on each RuleTile that needs it (or have it automatically done like you implied it should be working) rather than having to refresh the entire tilemap. I haven't scaled my tilemap to the final (and very large) size, but I imagine RefreshAllTiles won't be as performant as manually updating only those which were affected.
from 2d-extras.
That sounds like a bug then as you should not need to make use of tilemap.RefreshAllTiles in this case.
Would it be possible to share your RuleTile setup or your project through the Unity Bug Reporter?
from 2d-extras.
I feel dumb... I setup an example project from scratch and it all worked as you described. I realized the issue in my original project is that I was creating a new RuleTile instance from the ScriptableObject every time I place a new RuleTile instead of reusing it.
Long story short: it works if you do it properly. Thanks again for all your help Chuan, and sorry for not realizing I was doing something incorrectly.
from 2d-extras.
Related Issues (20)
- Prefab brush is not showing or working both are error HOT 1
- Error message after install, package not loaded HOT 1
- GridInformationKey should implemented IEquatable<GridInformationKey> and override GetHashCode() to avoid GC alloc HOT 1
- 2D Game Kit errors HOT 5
- unity 2021 package missing files HOT 1
- GridInformation.cs error : The name 'HashCode' does not exist in the current context HOT 6
- Editor Warning On Creation: No script asset for RuleTile. HOT 4
- GameObject Brush paint incorrect position when Cell.Position.y < 0 HOT 2
- New transform of rule tile: rotate and mirror HOT 6
- 2021.1.22f1 HashCode Error HOT 2
- NullReferenceException when using Tile Palette HOT 3
- Gameobject-Tiles and Tile Palette Preview HOT 1
- Mixing Tiles HOT 3
- I have an error. HOT 1
- Error deleting RuleTile with GameObject during physics callback HOT 2
- RuleTile with sibling layer tilemaps? z-axis siblings? HOT 1
- PopulateRuleOverideTileWizard can't work right HOT 8
- Animated Tile Expansion
- Tilemap renderer cannot be refreshed after deletion HOT 2
- Request Special Rule Tile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 2d-extras.