Search Unity

Runtime Level Design

Discussion in 'Assets and Asset Store' started by XGT08, Jan 17, 2016.

  1. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    In order to support Undo/Redo for a particular action, you need to implement the IUndoRedoAction interface. If you take a look inside the UndoRedoActions.cs file, you can find a few examples for some of the built-in actions that RLD supports.

    I am going to give you a simple and untested example. Let's assume you would like to change the color of material and would like to undo/redo such an action. You would do something like this:

    Code (CSharp):
    1. public class MaterialColorChangeAction : IUndoRedoAction
    2. {
    3.       private Material _targetMaterial;
    4.       private Color _newColor;
    5.       private Color _previousColor;
    6.  
    7.       public MaterialColorChangeAction(Material targetMaterial, Color newColor)
    8.       {
    9.            _targetMaterial = targetMaterial;
    10.            _newColor = newColor;
    11.            _previousColor = _targetMaterial.color;
    12.       }
    13.  
    14.       public void Execute()
    15.       {
    16.            _targetMaterial.color = _newColor;
    17.       }
    18.  
    19.       public void Undo()
    20.       {
    21.              _targetMaterial.color = _previousColor;
    22.       }
    23.  
    24.       public void Redo()
    25.       {
    26.            _targetMaterial.color = _newColor;
    27.       }
    28. }
    After you have created this class (I suggest you create a file of your own in which you store all your action classes), you should write the following code whenever you need to change the color of a material:

    Code (CSharp):
    1.  
    2. var changeColorAction = new MaterialColorChangeAction(myMaterial, newColor);
    3. changeColorAction.Execute();
    4.  
    This should work nicely. The code isn't tested, but let me know if you have any further questions.
    Note: In the Undo/Redo functions, you could test if the target material is null before using it just in case the material is destroyed in the meantime.

    Cheers,
    Andrew
     
  2. ihsan07

    ihsan07

    Joined:
    Mar 28, 2016
    Posts:
    17
    Hi XGT08. I want to start object to object snap session from scripting. Can you tell me how? I didn't see in docs.
    Edit: Found it! Nevermind. For those who needs this, call Begin() method in Object2ObjectSnapSession.cs. Have a great day!
     
    Last edited: Feb 14, 2021
  3. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    Hi Andrew,
    we have a weird issue currently.. I hope you have an idea how to solve that..
    Some runtime instantiated prefabs can be clicked normally and everything works fine, but some however do not respond to the left mouse button when you click on them ...only clicking and than dragging works however to select it..

    Do you have any idea why this is happening?

    EDIT: First I thought it´s related to RTObjectSelection.cs or RTObjectSelectionGizmo.cs
    than I compared a pretty old RLD-Version with 2018.2 and the exact same model which causes issues during the selection in 2019.4 can be selected with the older RLD in 2018.2
    I also exported different FBX-Versions, but it looks like it´s not related to that.

    I took a simple Cube and exported it as a fbx than imported it to unity and created a prefab out of it with and without textures (same effect on both) as soon as I instantiate the cube, it can´t be selected with one single left mouse button click (only dragging can select it)

    That´s a pretty annoying bug currently.. I hope you have an idea how to fix that..
     
    Last edited: Mar 1, 2021
  4. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    @XGT08 I just uploaded some files and send that via private messsage here, where you can replicate that bug. It would be very nice if you can take a look at that - thx
     
  5. larry2013z

    larry2013z

    Joined:
    Apr 14, 2020
    Posts:
    36
    Hi Andrew, I just installed Runtime Level Design in Unity 2020.2.6, Built-in Render Pipeline, and I am getting the following error:

    Assets\Runtime Level Design\Scripts\Gizmos\Scene Gizmo\RTSceneGizmoCamera.cs(2,29): error CS0234: The type or namespace name 'Universal' does not exist in the namespace 'UnityEngine.Rendering' (are you missing an assembly reference?)

    I'm not supposed to install the Universals RP am I? I want to use the Built-in RP.

    Can you please let me know how to fix this error?
     
    Last edited: Mar 8, 2021
  6. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi Larry,

    You can safely remove the using UnityEngine..Rendering.Universal; line and it should work. I must have forgotten it there somehow. I will update the pack.

    Cheers,
    Andrew
     
  7. larry2013z

    larry2013z

    Joined:
    Apr 14, 2020
    Posts:
    36
    I removed the UnityEngine..Rendering.Universal; line and the following errors occurred:

    Assets\Runtime Level Design\Scripts\Gizmos\Scene Gizmo\RTSceneGizmoCamera.cs(72,17): error CS0246: The type or namespace name 'UniversalAdditionalCameraData' could not be found (are you missing a using directive or an assembly reference?)

    and

    Assets\Runtime Level Design\Scripts\Gizmos\Scene Gizmo\RTSceneGizmoCamera.cs(72,65): error CS1061: 'Camera' does not contain a definition for 'GetUniversalAdditionalCameraData' and no accessible extension method 'GetUniversalAdditionalCameraData' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)

    and

    Assets\Runtime Level Design\Scripts\Gizmos\Scene Gizmo\RTSceneGizmoCamera.cs(73,38): error CS0103: The name 'CameraRenderType' does not exist in the current context
     
  8. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi Larry,

    I've sent you an e-mail with the updated pack.

    Cheers,
    Andrew
     
  9. larry2013z

    larry2013z

    Joined:
    Apr 14, 2020
    Posts:
    36
    Thanks Andrew, amazing support as always!
     
    Last edited: Mar 8, 2021
  10. larry2013z

    larry2013z

    Joined:
    Apr 14, 2020
    Posts:
    36
    HI Andrew,

    I downloaded RLD version 2.3.1 today.


    1) I cannot get undo to work in any mode.

    For instance if I duplicate an object and move it and then LCTRL + Z nothing happens

    Likewise if I am in extrude mode and do an extrusion and then LCTRL + Z nothing happens


    2) Once I hit Q to get into Extrude mode, how do I get back into regular selection mode?

    I tried hitting Q again by that does not work. I checked the documentation but its not mentioned there (also the documentation does not say to hit Q but I picked that up from our video)

    Thanks,

    -Larry
     
  11. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Replied via e-mail.
     
    larry2013z likes this.
  12. ktweedy1

    ktweedy1

    Joined:
    Apr 16, 2010
    Posts:
    26
    Just downloaded the most recent version. On the camera is says missing script. Everything I have tried seems to be working, is there suppose to be a script there?

    upload_2021-3-16_8-40-19.png
     
  13. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    RLD does not attach any scripts to existing game objects. It just creates its own objects and attaches any needed scripts to them. In your case, I believe you had a script attached to your camera and then you probably deleted the script from your project.

    Camera setup is discussed here.
     
  14. ktweedy1

    ktweedy1

    Joined:
    Apr 16, 2010
    Posts:
    26
    I deleted the scene and re-imported and when I look at the scene this is what I see. You can confirm that you don't have any scripts attached to the camera in your demo?
     
  15. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hmm... Just took a look at this and it seems there was a script related to the Universal Render Pipeline attached. Send me an e-mail please at octamodius@yahoo.com and I will send you the updated pack.

    Cheers,
    Andrew
     
  16. marcjammy

    marcjammy

    Joined:
    Aug 26, 2019
    Posts:
    13
    Can I ask - how can I turn EVERYTHING else off, and just use the gizmos? I tried switching off various components but it breaks and they seem to rely on each other.

    I literally just need to use the gizmos - no selection, no camera, no grid, etc... is there a way to do this?
     
  17. CastleSeven

    CastleSeven

    Joined:
    Jan 24, 2018
    Posts:
    6
    Hi Andrew - I have an Empty Gameobject (L_Base Layer) setup as an Object Group, and I have three game objects that are children of that L_Base Layer object, but the selection behavior is not acting like I thought it would. When trying to select one of the three objects (Barrel_Red_Rusty), the parent object is selected. Am I missing something? Unity 2018.4.24f1.

    upload_2021-4-7_14-50-32.png
     

    Attached Files:

  18. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    Objects marked as object groups will not be selected. Do you mean that when you select one of the children, it also selects the parent object group? (in this case L_Base Layer)
     
  19. CastleSeven

    CastleSeven

    Joined:
    Jan 24, 2018
    Posts:
    6
    Correct - when selecting a child of L_Base Layer, the child itself was not selected. The Translate gizmo that appeared after clicking on a single child translated the entire group.
     
  20. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    I just created a similar situation in the demo scene and it seems that in my case this behaves as expected. I can select the children, but I can not select the parent of the children which was marked as an object group.

    Can you maybe provide a short recording of the issue?

    Thanks,
    Andrew
     
  21. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    Hi Andrew,
    can you please let me know how we can disable the RLD selection of all objects, without disabling the whole RLDGameObject (so the Camera movement should stay) - it should be disabled for everything via script... so the idea is to disable all gizmos and selection of prefabs in the scene without disabling the camera functionality

    any idea how to do that?
     
    Last edited: Apr 12, 2021
  22. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    You can write: RTObjectSelection.Get.SetEnabled(false);
     
  23. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    awesome, exactly what I was looking for!

    Thank you very much :)
     
  24. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67
    hi,
    can we instantiate reflection probes at runtime with RLD? I tried that but no gizmos appear..
    any idea how to achieve that?
     
  25. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hello,

    Light probes are not supported. You can however create them and use a scfipt yo draw a representation in OnRenderObject callback.
     
  26. xkingjohnx

    xkingjohnx

    Joined:
    Feb 22, 2016
    Posts:
    67

    hey thank you. I will try that out!

    There is currently another issue, which is causing me headaches

    I am using this asset: https://assetstore.unity.com/packages/tools/utilities/ultimate-lod-system-mt-170425#description
    Whenever I add the LOD script to any prefab and instantiate that at runtime, the instantiated prefab can´t be selected with the left mouse button click (but if I click the left mouse button and hold/drag it over the prefab, it will be selected).
    The selection works fine, if there´s no LOD-Script attached to the prefab, though..

    Do you have a fix for this? What is causing that? Any idea?

    Many thanks in advance


    _______________________

    EDIT:

    I noticed this only happens when LOD1 and LOD2 are active, when LOD3 is active, the selection with the left mouse button works fine, though..

    any idea how to fix this?
     
    Last edited: May 4, 2021
  27. Juaprebo

    Juaprebo

    Joined:
    Nov 15, 2014
    Posts:
    19
    Hi! I need to use this plugin in Unity 2017.4.40 LTS. It is possible to get a plugin version for this Unity version?
     
  28. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hello,

    Thanks for contacting me :)

    I'm afraid this is not possible. The minimum supported version is the one written in the pack description: 2019.4.12

    Cheers,
    Andrew
     
  29. Alfred85

    Alfred85

    Joined:
    Aug 3, 2018
    Posts:
    1
    Hi! I'm currently working on Unity 2019.4.26f1.
    I've edited the RTPrefabLibDbUI but everytime I use it into Unity it works correctly. Whenever I build it on Windows, the prefabs in the menu don't appear. Also, I need to bind the keys on the UI, is there a way to do it? Thanks in advance

    EDIT: I tried to log the build, and it gives a NullreferenceException on the RTPrefaLibDbUI. I don't know what to do.
     
    Last edited: May 16, 2021
  30. Juaprebo

    Juaprebo

    Joined:
    Nov 15, 2014
    Posts:
    19
    Hi, thanks for the answer. I wondering why is not possible to porting the plugin to an older version, can you tell me why? I need it the plugin, and I'm thinking on make the porting by my own. Do you think if its possible?
     
  31. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Hi there @XGT08!

    Currently in the process of updating from an old version of Runtime Transform Gizmos to Runtime Level Design. So far so good, but how do I disable this thing?



    Even if I disable the spawned camera under RTGizmoEngine, events will still fire when clicking corner. If disabling RTGizmoEngine game object, a ton of errors will appear.

    I also wonder what has happened with OnAlteredByTransformGizmo in IRTObjectSelectionListener (IRTEditorEventListener). It's no longer there. What is the recommended way to receive events on a specific object for transform manipulations?

    All the best.
     
    Last edited: Sep 11, 2021
  32. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there Sunny,

    Regarding the scene gizmos, you have to do it from script like this:
    Code (CSharp):
    1. RTGizmosEngine.GetSceneGizmoByCamera(RTFocusCamera.Get.TargetCamera).SetEnabled(false);
    Regarding the listener class, it has been replaced with IRTTransformGizmosListener. You can check out the doc here:
    https://rld.readthedocs.io/en/latest/IRTTransformGizmoListener/

    I think you need the OnTransformed function from the IRTTransformGizmoListener interface.

    Cheers,
    Andrew
     
    SunnySunshine likes this.
  33. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    @XGT08

    Thank you so much!
     
    XGT08 likes this.
  34. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Unfortunately, that code doesn't seem to work. SetEnabled doesn't exist in ISceneGizmo (what's returned by GetSceneGizmoByCamera).

    Sorry, it was as simple as doing this:
    Code (CSharp):
    1. RLD.RTGizmosEngine.Get.GetSceneGizmoByCamera(RLD.RTFocusCamera.Get.TargetCamera).OwnerGizmo.SetEnabled(false);
    Also I have 1 feature request:

    I my case, the box select doesn't work as desired because I have mesh assets that are scaled billboards, so their bounding box don't align with what they actually look like on screen. I wish there was a way to let the colliders dictate the rect size to be compared with box select, or simply use the position point to check if inside box select.

    All the best.
     
  35. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
    Hello, when I go into "Surface Snapping" mode by pressing the "C" key, I get a null pointer exception. If I press the "C" key while no object is selected, it seems to have no effect. If I press the "C" key while an object is selected I get the null pointer exception.

    I verified that Camera.current is null in the line where the exception is thrown (line 137 of ObjectGrabSession.cs)

    RLD Camera Null Exception.png

    So, I figured that maybe that RLDFocusCamera was not set properly. However, I verified that the Camera was indeed set. Also, I verified that it was the correct Camera (there is only one camera in my scene).

    RLD Camera Set.png


    I am running Unity 2020.3.19f1, URP 10.6.0 and RLD 2.3.1.

    Any idea what may be going on?

    thanks,
     
  36. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    Looks like it has to do with URP where Camera.current no longer works as in the Standard pipeline. I will take a look at this and get back to you when I have a solution ready.

    Thanks,
    Andrew
     
  37. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
    ok, thanks. For now I have commented that code out and I can get the surface snapping to work. Looking forward to a fix as there are other areas like object2object snapping that are also impacted.

    Another question. I am trying to get surface snapping to work on a set of "stairs". So, I want the object to only snap to the horizontal part of the stairs and not the vertical part. I was able to sort of accomplish this by covering the horizontal part of a stair with a thin slab and have only those slabs be allowed "snappable surfaces".

    The transform of my object is at the bottom of my object. However, I noticed a couple of things. The "snap point" is, in general translated from the object transform based on where the user first clicks. This makes it so that while the mouse is over (say) Stair 1, the object snaps to (say) Stair 2. Is there a way to have the "snap point" always coincide with the object root transform regardless of where the user first clicked?

    A related issue with surface snapping is when the user sequentially moves the mouse over areas that are snappable and non-snappable. When the user's mouse is moving over the snappable area, the snapping works fine (other than the point offset issue mentioned above). However, the behavior is odd when the user's mouse goes over the non-snappable area, the results are kind of indeterminate. (maybe its dropping to the Grid below?) At least for my game, a useful behaviour would be that when the mouse is over a non-snappable area, the object stays at the "last good" snap point and then suddenly "jumps" when a new "good snap point" happens.

    thanks
     
  38. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    @villaman

    Hi there,

    There is an update live now which fixes the issue you were having.

    Regarding object to object snapping, I am not sure I would change the behavior. It is a bit tricky to get right and I am aware that it might not always produce the desired results with some prefabs. However, I think it does work really well as it right now with most prefabs.

    I will take a look over the code to see if there is something I can change, but I won't make any promises.

    Cheers,
    Andrew
     
  39. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    69
    ok, thank you.
     
  40. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    I found a bug.

    Steps to reproduce:

    1. Initialize a new scene with RLD.
    2. Set RTScene to use Unity Colliders mode.
    3. Run the scene.
    4. Create a new cube (in unity editor).
    5. Box select anywhere on the screen.
    6. Remove the cube (in unity editor).
    7. Box select anywhere on the screen.

     
  41. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    I've tried to reproduce this, but it seems it doesn't happen for me. I can see an error message, but I can't see the name of the file producing the error. Can you send me the name of the file that throws the error?
     
  42. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    I'm not on my computer right now. I'll do it when I can.

    Was the cube you created visible to the game camera? I think it needs to be for this to happen.

    Also must be using unity colliders.
     
  43. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
  44. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Thanks. The bug was reproduced and fixed. The update should be live in a little while.
     
    SunnySunshine likes this.
  45. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    It works. Thank you!
     
    XGT08 likes this.
  46. jh092

    jh092

    Joined:
    Sep 2, 2018
    Posts:
    55
    Hi there and thank you for your asset.

    May I ask please, I am trying to prevent some selected objects from being deleted. My logic was to hook in to the OnWillBeDeleted event, find everything selected via Get.SelectedObjects, then perhaps use Get.RemoveObjects to create the list of objects that I don't want deleted.

    Alas my cunning plan doesn't work, by the time the OnWillBeDeleted event fires the selection list is empty.

    Please can you advise how I can prevent some selected objects from being deleted while still allowing other selected objects to be deleted?

    Many thanks and best wishes from Australia

    John
     
  47. lizzilizzi

    lizzilizzi

    Joined:
    Apr 5, 2015
    Posts:
    7
    Loving the asset!

    I've noticed the prefab preview images do not always have the best camera angle for the prefab (E.g. One of my prefabs, the image is showing from below the asset, not the side view). Do you have any advice on how I could improve this?

    I've searched if there is a way to change the camera angle of the prefab previews but could not find anything useful.

    My other solution is to use an image attached to the prefab. If I wanted to add in some code to use an image attached to the prefab instead of the prefab preview camera, which script would I need to look at?

    Thank you, and Merry Xmas!
     
  48. lizzilizzi

    lizzilizzi

    Joined:
    Apr 5, 2015
    Posts:
    7
    Ok, I was able to find a solution.

    There may be a more efficient way to do it, but the way I did it was to add a disabled Canvas and disabled Image to each prefab that I wanted to have a better preview image.

    In the RTPrefabScrollView script, I amended some of the code in AddPrefabPreview to the following:

    Code (CSharp):
    1. Image image = previewButton.GetComponent<Image>();
    2.             if (image != null && prefab.UnityPrefab.GetComponentInChildren<Image>(true) != null)
    3.             {
    4.                 image.sprite = prefab.UnityPrefab.GetComponentInChildren<Image>(true).sprite;
    5.             }
    6.             else
    7.             {
    8.                 if (image != null) image.sprite = prefab.PreviewSprite;
    9.             }
    So it will look for an image in the disabled children of the prefab to use as the preview, and if not found, it will use the default unity prefab preview.
     
  49. lizzilizzi

    lizzilizzi

    Joined:
    Apr 5, 2015
    Posts:
    7
    Heya, did you end up finding a solution to this?

    I am having the same issue.
     
  50. XGT08

    XGT08

    Joined:
    Aug 1, 2013
    Posts:
    1,905
    Hi there,

    I am guessing that it has to do with the mesh not being readable. When importing a mesh in Unity, click on the mesh asset, and make sure the read-write enabled toggle is checked. This should work.

    Cheers,
    Andrew
     
    lizzilizzi likes this.