Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefab brush throw an error #64

Closed
AndreyChernykh opened this issue Dec 6, 2018 · 9 comments
Closed

Prefab brush throw an error #64

AndreyChernykh opened this issue Dec 6, 2018 · 9 comments

Comments

@AndreyChernykh
Copy link

AndreyChernykh commented Dec 6, 2018

Unity 2019.1.0a7

Hi! I'm trying to use prefab brush in my project as shown in official unity tutorial here -> https://unity3d.com/learn/tutorials/topics/2d-game-creation/custom-tilemap-brush-spawn-prefabs?playlist=17093 but it doesn't work.

It just places one object and then it doesn't paint more prefabs and there are thrown some exceptions in the console

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.PrefabBrush.Paint (UnityEngine.GridLayout grid, UnityEngine.GameObject brushTarget, UnityEngine.Vector3Int position) (at Assets/vendor/2d-extras/Tilemap/Brushes/Prefab Brush/Scripts/Editor/PrefabBrush.cs:20)
UnityEditor.PaintableSceneViewGrid.Paint (UnityEngine.Vector3Int position) (at C:/buildslave/unity/build/Modules/TilemapEditor/Editor/Managed/Grid/PaintableSceneViewGrid.cs:169)
UnityEditor.PaintableGrid.HandleBrushPaintAndErase () (at C:/buildslave/unity/build/Modules/TilemapEditor/Editor/Managed/Grid/PaintableGrid.cs:370)
UnityEditor.PaintableGrid.OnGUI () (at C:/buildslave/unity/build/Modules/TilemapEditor/Editor/Managed/Grid/PaintableGrid.cs:100)
UnityEditor.PaintableSceneViewGrid.OnSceneGUI (UnityEditor.SceneView sceneView) (at C:/buildslave/unity/build/Modules/TilemapEditor/Editor/Managed/Grid/PaintableSceneViewGrid.cs:81)
UnityEditor.SceneView.CallOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2912)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2159)
UnityEditor.SceneView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2020)
@lijinglue
Copy link

reproduced in 2018.3.0f1

@ChuanXin-Unity
Copy link
Collaborator

Hi, this will be fixed in a future version of Unity (both for 2018 and 2019 lines)!

@AntonStrickland
Copy link

The error happens because after placing the object, the active tilemap is set to "Nothing" and so you get a null reference exception. Until there is a real fix, you can get around it by resetting the tilemap (click away from it and then click back on it) every time you place an object.

@LastAssertor
Copy link

LastAssertor commented Dec 15, 2018

Unity 2018.3.0f2

i try to modify ‘PrefabBrush.cs’, it seems solved, but can not limited to children of the currently selected GameObject.

public class PrefabBrush : GridBrushBase
=>
public class PrefabBrush : GridBrush

then

public class PrefabBrushEditor : GridBrushEditorBase
=>
public class PrefabBrushEditor : GridBrushEditor

then

protected void OnEnable()
{
m_SerializedObject = new SerializedObject(target);
=>
protected override void OnEnable()
{base.OnEnable();
m_SerializedObject = new SerializedObject(target);

@DanarKayfi
Copy link

reproduced in 2018.3.0f2

@Krummelz
Copy link

Krummelz commented Jan 5, 2019

Unity 2018.3.0f2

i try to modify ‘PrefabBrush.cs’, it seems solved, but can not limited to children of the currently selected GameObject.

public class PrefabBrush : GridBrushBase
=>
public class PrefabBrush : GridBrush

then

public class PrefabBrushEditor : GridBrushEditorBase
=>
public class PrefabBrushEditor : GridBrushEditor

then

protected void OnEnable()
{
m_SerializedObject = new SerializedObject(target);
=>
protected override void OnEnable()
{base.OnEnable();
m_SerializedObject = new SerializedObject(target);

This solved it for me! Thanks!

@bqback
Copy link

bqback commented Jan 7, 2019

Unity 2018.3.0f2

i try to modify ‘PrefabBrush.cs’, it seems solved, but can not limited to children of the currently selected GameObject.

public class PrefabBrush : GridBrushBase
=>
public class PrefabBrush : GridBrush

then

public class PrefabBrushEditor : GridBrushEditorBase
=>
public class PrefabBrushEditor : GridBrushEditor

then

protected void OnEnable()
{
m_SerializedObject = new SerializedObject(target);
=>
protected override void OnEnable()
{base.OnEnable();
m_SerializedObject = new SerializedObject(target);

Thank you for this fix (worked on 2018.3.0f2)! Although there's a problem: while the brush no longer throws an error and resets, it now draws a new sprite for every little movement of my mouse cursor within a single tile (so rapidly moving my mouse back and forth across a few pixels creates dozens of the same object), which I doubt to be the intended effect, Same goes for the eraser -- moving the eraser back and forth within a single tile allows me to quickly erase all of those excess sprites.

@zastrowm
Copy link

zastrowm commented Jan 8, 2019

@bqback I solved that problem by Erasing before painting. Something like this before Undo.MoveGameObjectToScene:

Erase(grid, brushTarget, position);

@ChuanXin-Unity
Copy link
Collaborator

This has been fixed in Unity 2018.3.4f1, or you can continue to use the PrefabBrush as modified!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants