Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] SpriteLights

Discussion in 'Assets and Asset Store' started by Elecman, Oct 10, 2015.

  1. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    Also, placing RunwayLights, with default settings and position, gives me this error:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. SpriteLights.GetScaleFactor (System.Single FOV, System.Single screenHeight) (at Assets/SpriteLights/Scripts/SpriteLights.cs:50)
    3. SpriteLights.Init (System.Single strobeTimeStep, System.Single globalBrightnessOffset, System.Single FOV, System.Single screenHeight) (at Assets/SpriteLights/Scripts/SpriteLights.cs:57)
    4. RunwayLights.Update () (at Assets/SpriteLights/Scripts/RunwayLights.cs:84)
    5.  
    The demo scenes work fine but when I try to implement it into my scene I get this error - this only happens with Runway Lights. -- City Lights work fine, apart from the issue as explained in my text above. . I am not using the canvas script from your sample scene as I don't need it -- is it calling for it?
     
  2. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    The runway lights are just a game object, so it can be positioned as such. If you want to create the runway lights in code, the RunwayLights.cs (I think that's what it's called as I don't have it with me now) has a function that takes a position as an input.

    If the look of the lights is not correct, the setup function is probably not correctly initialized. Have a look at the first post of this thread, in the troubleshooting section. Let me know if you can get it to work.
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    As for the NullReferenceException, can you email me a small repo so I can have a look at it?
     
  4. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    I am also wondering how to place 2 runway Lights [airports], one for take-off and one for landing, into the same scene - is that possible?
     
  5. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    I did figure out the placement meantime - works great - but the error is the same
     
  6. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    yes, ill send you an email with the NullReferenceException: error -- but here's basically what I am doing...
     

    Attached Files:

    • 0.JPG
      0.JPG
      File size:
      158.4 KB
      Views:
      265
    • 1.JPG
      1.JPG
      File size:
      14.3 KB
      Views:
      266
    • 2.JPG
      2.JPG
      File size:
      121.7 KB
      Views:
      266
    • 3.JPG
      3.JPG
      File size:
      110.7 KB
      Views:
      258
    • 4.JPG
      4.JPG
      File size:
      191.4 KB
      Views:
      259
  7. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    error
     

    Attached Files:

    • 5.JPG
      5.JPG
      File size:
      192.2 KB
      Views:
      261
    • 6.JPG
      6.JPG
      File size:
      20.3 KB
      Views:
      254
  8. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    All works now - placement of runway is good - city lights are now in their full glory :) - I was also able to make a build even though the error prints the same - it seems to have no negative effect on the build whatsoever. I do notice that my GPU struggles more then usual after the build - I'm usually @ 30% - now I am on 75% and above -- its possible that the error loops throughout the game play... not sure. Is the RunwayLight script looking for the reference object in the sample scene (distance to airport) ? I haven't checked yet.
     
  9. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    Edit: ...the problem is it initializes in the editor - it does not in the build -- just random dots
     
  10. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    I am unable to reproduce the problem with the NullReferenceException.

    What Unity version are you using?

    I didn't receive the repo. If you can send it to me, that would help a lot. Or if you can't send me a repo, make a short youtube video with step by step instructions how to end up with the error.

    About the random dots, can you make a screenshot of the build where the problem shows up? Did you setup the correct parameters in the Init() function?
     
    Last edited: Feb 20, 2022
  11. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    388
    @Elecman

    Hi. This is my first attempt to use this marvelous asset. But I have two small consol errors in Unity 2021.3.5f1 LTS. Any help would be greatly appreciated. Thank you in advance!

     
  12. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    388
    @Elecman I found another script with the same name. After erasing it, everything is running well.
    Thanks!

    Small question. Can the provided Spritelight scenes be use in our Production? Short movies, games, etc... Thank you!
     
    Last edited: Aug 1, 2022
  13. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Yes, you can use the scenes in any way without any restrictions.

    You can also make similar custom scenes using open streetmaps and mapity. There is a description in the documentation on how to do that.
     
  14. Avedis

    Avedis

    Joined:
    Jan 12, 2013
    Posts:
    24
    Hello, I'm trying to create sprite light meshes however when I use the editor script (Window->SpriteLights) it creates it in the editor but I am unable to create a prefab or export it. It seems to generate an empty mesh, is there a fix for this? I would need to be able to create a prefab that I could use in multiple scenes.

    I have tested this in Unity 2019.4.3 and 2021.3.9.

    Thank you. spritelights1.PNG spritelights2.PNG
     
  15. bitbarrel

    bitbarrel

    Joined:
    Nov 14, 2013
    Posts:
    2
  16. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    I managed to fix my account login (google authenticator time sync issue), and I finally managed to install Unity again, so here we go:

    To save a sprite light as a prefab when it's created in the Editor, do this:

    Open the file SpriteLightsEditor.cs

    Find this line:

    Code (CSharp):
    1. SpriteLights.CreateLights("ConvertedLights", lightData, mat, UnityEngine.Rendering.IndexFormat.UInt16);
    Replace it with this:

    Code (CSharp):
    1. //Create the light mesh.
    2. GameObject[] lightObjects = SpriteLights.CreateLights("ConvertedLights", lightData, mat, UnityEngine.Rendering.IndexFormat.UInt16);
    3.  
    4. for (int i = 0; i < lightObjects.Length; i++)
    5. {
    6.     //Save the mesh to disc.
    7.     AssetDatabase.CreateAsset(lightObjects[i].GetComponent<MeshFilter>().sharedMesh, "Assets/" + lightObjects[i].name + ".asset");
    8.     AssetDatabase.SaveAssets();
    9.  
    10.     //Save the game object to disc.
    11.     PrefabUtility.SaveAsPrefabAsset(lightObjects[i], "Assets/" + lightObjects[i].name + ".prefab");
    12. }
    This will create a prefab and associated mesh in the root folder when creating spriteLights via the editor script.

    Edit:
    Even better, here is the script with an option on the dialog:
    https://drive.google.com/file/d/1Oa2LJQW9U8rMPZvVELa212g1BG6bIFDI/view?usp=sharing
     
    Last edited: Mar 11, 2023
    hopeful likes this.
  17. Verne33

    Verne33

    Joined:
    Apr 12, 2020
    Posts:
    32
    Hello sir,
    Wondering if you have a recommendation for efficient way to draw lines between the light points in SpriteLight meshes? I'd like to do constellation style, connecting the dots. But would have a lot of lines at one time, so wondering if it's easy to modify the shader somehow to do this, instead of having to use LineRenderers and store more memory.
    Thanks for any insights and help!
     
  18. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    That would be a totally different shader. It's best to look for existing line renderers in the asset store. You should pick one which can be baked into a mesh, possibly using another asset such as meshbaker.
     
    Verne33 likes this.
  19. Zer0_obscura

    Zer0_obscura

    Joined:
    Nov 20, 2013
    Posts:
    13
    Hello, This plugin is wild. The scenes are really impressive. Could I attatch some lights to the bones of a character model? Im wanting the animated character to have a few single led lines on the chest and arms that has a few different strobe and gradient patterns that I can swap between on a button click. Any help would be greatly appreciated.
     
  20. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    The lights are mesh objects, so if you can attach a mesh to a bone of a character, you should be able to attach a sprite light object also.

    One of the shaders is a strobe light, but a gradient pattern effect requires a shader modification.
     
  21. Zer0_obscura

    Zer0_obscura

    Joined:
    Nov 20, 2013
    Posts:
    13
    Any idea what I would need to modify in that regard? Is this a shader graph thing? Or shader code thing? Sorry to be a bother.
     
  22. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    It's shader code, not a graph. Maybe looking at an existing gradient strobing shader would be a good start.
     
  23. Verne33

    Verne33

    Joined:
    Apr 12, 2020
    Posts:
    32
    Hi, regarding this part of your original post

    If you want to change the light mesh at runtime, don't create a new light mesh and destroy the old one as this is very slow. Instead, keep a copy of the mesh data in an array, modify the array (preferably using ECS), then update the light mesh with the new mesh data.

    What is the recommended way to "update the light mesh" with my modified array?

    Thank you
     
  24. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Just copy a new array into the mesh array. It's no different than updating a regular mesh, except there is no need to recalculate normals or bounds.

    For details, search for "Unity update mesh array"
     
    Verne33 likes this.
  25. Verne33

    Verne33

    Joined:
    Apr 12, 2020
    Posts:
    32
    Specifically what I'm confused about is - SpriteLights.CreateLights returns a Gameobject array, but the GameObject with the mesh is created at runtime. How do I get access to that GameObject and thus the generated mesh?

    I need to do this at runtime. Sorry if it's a dumb question, I'm relatively inexperienced with meshes
     
  26. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Can you post some example code to see what is it exactly you are trying to do? Getting access to a GameObject and the attached mesh from a SpriteLights object is no different than any other Unity operation getting access to a GameObject with a mesh. Have a look at tutorials that explain how to get a mesh from a GameObject, then post some code here and I'll try to get you going.
     
  27. Verne33

    Verne33

    Joined:
    Apr 12, 2020
    Posts:
    32
    Let me try to explain another way.....

    The problem is I can't see in your code where the GameObject is instantiated, and so I can't efficiently find and reference it at runtime.

    Spritelights.CreateLights seemingly instantiates a GameObject w/ the mesh. However Spritelights.CreateLights doesn't return a GameObject, rather a GameObject []. So I am wondering where this single GameObject with the mesh is instantiated in the code so I can reference it.

    I guess I could loop through all GameObjects searching for the name that I passed in, but that would be inefficinet
     
  28. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
    Spritelights.CreateLights indeed returns an array of GameObjects. However, if you don't create a huge amount of lights, it will only return one GameObject in the array. Just get the GameObject in array index 0 and you should be golden.
     
    Verne33 likes this.