Search Unity

[RELEASED] uConstruct - Fully generic, socket based runtime construction system

Discussion in 'Assets and Asset Store' started by ElroyUnity, Oct 17, 2015.

  1. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    I'm guessing it's something to do with this,
    Code (CSharp):
    1. public void UpdateNetworkedBuildingEvent(UpdateNetworkedBuilding evnt)
    2.         {
    3.             int id = evnt.buildingUID;
    4.             var building = GetEntity(id);
    5.  
    6.             if (building != null)
    7.             {
    8.                 building.AssingNetworkedHealth(evnt.health);
    9.  
    10.                 if (PhotonNetwork.isMasterClient)
    11.                 {
    12.                     evnt = new UpdateNetworkedBuilding();
    13.                     evnt.buildingUID = id;
    14.                     evnt.SendToAll();
    15.                 }
    16.             }
    17.         }
    new UpdateNetworkedBuilding() will have health==0, that doesnt seem right if were not trying to destroy the building
     
    ElroyUnity likes this.
  2. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Uhm checked the code and it looks fine...
    Make sure that the building.maxHealth is bigger than 0,
    and make sure that you don't decrease the health a few times (Accidently)


    other than that I looked through the code and it looks just fine...
     
  3. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    I'm having a problem where if i destroy one building and it triggers CheckForGround for second building and destroys it too, if i build something in the spot of that second building, it creates a new BuildingGroup there and adds that new building to it, instead of adding it to the existing one.
    ____________________________________________
    I think i fixed it,
    by actually calling
    Code (CSharp):
    1. rootBuilding.DestroyBuilding()
    in CheckForGroundCollision.cs instead of just
    Code (CSharp):
    1. rootBuilding.enabled = false;
    2. rootBuilding.DeAttachBuilding();
    3. Destroy(rootBuilding.gameObject, destroyDelay);
    So it has a chance to call OnDestroyEvent() and PhotonCloudBuilding.cs's
    Code (CSharp):
    1. OnDestroyEvent += () => PhotonCloudEntitiesManager.entities.Remove(this);
    which it wasnt calling before
     
    Last edited: Jan 23, 2019
    ElroyUnity likes this.
  4. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Thats a good catch, will add it in an update!
     
  5. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Another problem with building groups.
    Photon Cloud integration, using the save/load feature
    I save and load 4 different building groups, it saves and loads them all perfectly.
    But then if i load it all up, break an original piece in building of lets say group1 and then try to place something in its place, it doesnt add that new piece to group1, doesn't create a new building group, it adds it to a random neighboring building group that is way farther away than the current one for some reason
    ____
    and sometimes when i right-click to destroy a building, it destroys one from some other random building group instead of the one i clicked on
    _____
    so far i narrowed it down to GetEntity(id) in UpdateNetworkedBuildingEvent returning the wrong gameobject sometimes, probably related to when placedOn id == -1, cause it only happens to objects that are connected right to the object that is connected to a 'root' BaseSocket-only object in my scene, cause after it gets loaded it has placedOn id == -1
    ______
    actually it seems nothing to do with saving and loading, even when i place them by hand, originating from the root BaseSocket the bug still happens
    _______

    So i think the problem might be in the way we generate networkID's
    imagine this, our entity ids are {1 2 3 4 5}
    then i delete one building {1 2 4 5}
    and place a new one, it adds entity to list and generates id=entities.Count
    which makes it {1 2 4 5 5}
    id collision
    or am i missing something?

    Code (CSharp):
    1. PhotonCloudEntitiesManager.cs CreateNetworkBuildingEvent()
    2. entities.Add(building);
    3. evnt.id = entities.Count;
    4. ..
    5. building.networkedID = evnt.id;
    Code (CSharp):
    1. OnDestroyEvent += () => PhotonCloudEntitiesManager.entities.Remove(this);
     
    Last edited: Jan 26, 2019
    ElroyUnity likes this.
  6. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Yep argh, sorry for these issues. Will get you a code fix today when I get to the office :)

    Update - getting late and I probably wont get to a pc today. Will get you the fix tomorrow! Sorry :)
     
    Last edited: Jan 24, 2019
  7. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    433
    has anyone used this with ar core yet?
     
  8. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Hi, there is a bug where due to this code in CheckForGroundCondition.cs
    Code (CSharp):
    1. rootBuilding.OnPlacedOnChangedEvent += (BaseBuilding oldBuilding, BaseBuilding newBuilding) =>
    2.                 {
    3.                     if(newBuilding != null)
    4.                     {
    5.                         newBuilding.OnDeattachEvent += () => InitiateCondition(newBuilding);
    6.                     }
    7.                     if(oldBuilding != null)
    8.                     {
    9.                         oldBuilding.OnDeattachEvent -= () => InitiateCondition(oldBuilding);
    10.                     }
    11.                 };
    if you keep calling building.HandlePlacing (for example in the exampleBuilder script), it changes the placedOn variable, that calls this OnPlacedOnChangedEvent event, and code above keeps adding (+=) to the event handler, it piles up and you end up with an event handler with 10000 events registered and it gradually tanks the fps.

    About -100 fps every 5 seconds if you call HandlePlacing every FixedUpdate
    ______________________________
    I think i fixed it for now by replacing (CheckForGroundCondition.cs)
    rootBuilding.OnPlacedOnChangedEvent += (BaseBuilding oldBuilding, BaseBuilding newBuilding) =>
    with
    Code (CSharp):
    1.  
    2. rootBuilding.OnPlacedEvent += BuildingOnPlaced;
    3. private void BuildingOnPlaced()
    4. {
    5.       if (rootBuilding.placedOn != null)
    6.       rootBuilding.placedOn.OnDeattachEvent += () => InitiateCondition(rootBuilding.placedOn);
    7. }
    if i missed something and this change will have unforseen changes please let me know
     
    Last edited: Feb 1, 2019
    ElroyUnity likes this.
  9. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Yep that would work, but if you add a feature where you can move buildings after they are placed it will cause some issues.
    Btw thank you for mentioning all of these issues, I am working on an update now that includes all of them so if you find more let me know! (Of course even stuff you didn't fix)
     
  10. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    When a building snaps to a socket there seems to be 1 physics tick delay until it checks if it satisfies the collision conditions, i think its due to changing transform.position and then calling CheckConditions(), but the colliders dont have time to update their positions, because physics(collider positions) only update on FixedUpdate, not immediately after transform.position change.
     
    ElroyUnity likes this.
  11. ptaqq

    ptaqq

    Joined:
    Oct 19, 2018
    Posts:
    2
    Is there any tutorial on how to add a new prefab from the beginning?
     
    ElroyUnity likes this.
  12. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Yep, have you checked the video tutorials on the EEProductions youtube channel?
     
  13. ptaqq

    ptaqq

    Joined:
    Oct 19, 2018
    Posts:
    2
    Otherwise, to adjust the socket to the object I need to scale it manually? and whether I need to scale an object or a physical object ?
     
    Last edited: Feb 2, 2019
    ElroyUnity likes this.
  14. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Well, you do need to scale it manually but if you change the scale of the building it should adjust accordingly.
     
  15. zhouzhongcheng_sz

    zhouzhongcheng_sz

    Joined:
    Mar 9, 2015
    Posts:
    6
    I have very serious performance problem when I use load function in class BuildingGroupSaveData(public override void Load(BaseUCSaveData _data)). It will use 4-5 seconds to load all 35 objects(PhotonCloudBuilding) on pc platform.And it will use 20 seconds to load all 35 objects(PhotonCloudBuilding) on android device(cpu:Qualcomm 660).
    I will give a profile snap shot.

    profile-loadBuilding.png

    memory profile images which can show memory changes:




    Now I had found the reason:
    _instance = Resources.Load<PrefabDB>("UConstructPrefabsDatabase");
    is very slow. I had about 300 buildings in the PrefabDB.

    It seems that Unity load the mesh of all the buildings in the PrefabDB.
     
    Last edited: Feb 5, 2019
    ElroyUnity likes this.
  16. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Well that's because you have 300 buildings... Try to delete this object and recompile prefab database (Window/uConstruct/ Update Prefab Database), it might remove some unused structures.
    If that doesn't work, try to remove some structures from your assets folder (the demo folder for instance) and try to delete it again.

    Unfortunately its a unity bottleneck :/
     
  17. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    A small update -

    Working on a new version now that includes some fixes reported here in the forums, in the mails and also some bugs I found on my own including snapping issues, overlapping structures, issues with photon integration and also some garbage allocation in the demo building placer.

    Will let you guys now when its ready for submittion :)
     
  18. zhouzhongcheng_sz

    zhouzhongcheng_sz

    Joined:
    Mar 9, 2015
    Posts:
    6
    It will be very good that we have many buildings(eg 10000 buildings) in the Prefab Database,but we only use some of buildings(eg 30 buildings ) in a scene. And we will only load the assets of used buildings(30 builidngs) in this scene.

    In my project. I can have about 2000 buildings in the Prefab Database eventually. And I will use tens of these buildings in a scene.
     
    Last edited: Feb 5, 2019
    ElroyUnity likes this.
  19. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Uhmm well I can maybe use different prefab database for different scenes, I will start looking at a solution like that.
     
  20. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Hey i just want to suggest a feature:
    Would be useful to have a "Replace Socket" where you could replace the current building with a new one, that would snap to and highlight green on the already existing one.
    Primary use for me would be as an upgrade system like in Rust, from Wood Wall -> Stone Wall
     
    ElroyUnity likes this.
  21. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    uhmm thats interesting, will look into it.
    But for now you could just instantiate the building, set isBeingPlaced to false,
    then set snappedto and placedon the same as the old building
    and then destroy the old one
     
  22. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Any news on the update?
     
    ElroyUnity likes this.
  23. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    It's probably not going to be soon, got a few bugs I want to fix first for the update.
    But I will be happy to help you do it yourself for now as it's not that complicated :)
     
  24. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Please do share the bugs you found!:)
     
    ElroyUnity likes this.
  25. ChillyMcChill

    ChillyMcChill

    Joined:
    Nov 17, 2016
    Posts:
    57
    Hello again, have you been able to make that VR/VRTK demo?
     
  26. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Mostly stuff people found here in the last few posts, and some more such as issues with building rotations, settings not being saved properly, issues with PUN integration and more.

    Hoping to get them all out on a big update soon :)


    Sorry not yet - but I used uConstruct with VR in my game, its pretty simple.
    All you need to do is in the BuildingPlacer ->

    1) Change the ray origin (to one of your controllers)
    2) Change inputs to controller inputs

    and that's it :)
     
    Tethys likes this.
  27. gn0ll

    gn0ll

    Joined:
    Sep 29, 2016
    Posts:
    16
    Once I have built something, I am trying to store some simple data in a database to help me re-create the building when I re-join the game.

    As far as I understand, I need to store:
    1. prefabID
    2. position
    3. rotation
    4. placedOn
    5. snappedTo
    All of these are really easy to store except for the snappedTo. I would love to just have a 'socketIndex' or something on the socket (since the order of the sockets is always the same.

    Then my DB row would look like:
    Group | itemNum | prefabID | pos | rot | placedOn | snappedTo

    Then I could just read the table, loop through the results and easily rebuild any group/structure.

    Right now I am doing a ghetto loop to figure out the socket index, but just wanted to check if there is a better way. Thanks!

    Code (CSharp):
    1. // Loop through all the sockets on this building
    2.  for (int i = 0; i < currentBuilding.sockets.Length; i++)
    3.  {
    4.         if (currentBuilding.placedOn.sockets[i].name == currentBuilding.SnappedTo.name)
    5.         {
    6.             GameManager.instance.Log4("snappedTo (loop name): " + currentBuilding.placedOn.sockets[i].name);
    7.             GameManager.instance.Log4("snappedTo (loop index): " + i);
    8.             break;
    9.          }
    10. }
     
    Last edited: Feb 22, 2019
    ElroyUnity likes this.
  28. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    That's a good one, will add to the next version :)
     
  29. gn0ll

    gn0ll

    Joined:
    Sep 29, 2016
    Posts:
    16
    Amazing, thanks for the quick reply. My hack is working great so far, really love how easy your system is to work with. Ill post some GIFs in a few days :)
     
    ElroyUnity likes this.
  30. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Cheers :)
    Really appreciate it :D
     
  31. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Any updates on the next version?
     
    ElroyUnity likes this.
  32. drcfrx

    drcfrx

    Joined:
    Jan 26, 2013
    Posts:
    38
    I'm interested too since I'm going to finally try to implement the system in my game for real ^^
     
    ElroyUnity likes this.
  33. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Aim is in April! Hopefully mid-april
     
    drcfrx, Teila and julianr like this.
  34. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    146
    Any ideas if you will support Opsive's Ultimate Character Controller?
     
  35. Stanchion

    Stanchion

    Joined:
    Sep 30, 2014
    Posts:
    266
    Doesn't really have anything to do with the asset. You can use any arbitrary player controller with this.
     
  36. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    220
    Hey @ElroyUnity

    I am wondering if this asset is for me and was hoping you could answer that question:

    Here is my case:

    I would like to use this to place predefined objects (houses, fields etc) in my scene using a perspective camera (without a character in it)

    Just like an RTS.

    A few questions:

    -Does it support terrain flattening?
    -Does it support these already predefined prefabs?

    Thank you in advance
     
    ElroyUnity likes this.
  37. ScottPeal

    ScottPeal

    Joined:
    Jan 14, 2013
    Posts:
    33
    Can the author of this asset please consider adding support for uSurvival? It would be a good match and the author over at uSurvival is very active and helpful.
     
  38. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Hey -

    -Yes there is support for terrain flatterning, the current version's is a bit weird but the new one should be much better and smoother

    -Not really atm, maybe in the future :)
     
  39. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    At the moment because of the army and life stuff I don't have time to add new integrations. Currently focusing all of my free time which is already almost nothing on the new version... maybe in the future :)
     
    Tethys likes this.
  40. Tethys

    Tethys

    Joined:
    Jul 2, 2012
    Posts:
    666
    I just wanted to pipe in and confirm this. We also used VRTK for our VR game with Uconstruct. It was very easy to get this working by changing the ray origin to one of the controllers and then listen for the controller input. We also wired up the interface for selecting piece categories and piece types(with the up and down, left and right pads). We found Uconstruct to be very user friendly when it comes to modding it as we had to make modifications for our non VR game Astral Terra as well. Great product! also looking forward to getting the bug fixes, though I cringe because I have to comb through my custom code to make sure I don't overwrite anything on the update. Thanks again man!
     
    ElroyUnity likes this.
  41. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Haha happy to hear ;)
    Also, that's your chance to bring up any bugs you guys have noticed, I will be trying to fix all of them for the next update :)
     
  42. ScottPeal

    ScottPeal

    Joined:
    Jan 14, 2013
    Posts:
    33
    Understand. Thank you for your service!
     
    ElroyUnity likes this.
  43. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Hi, I'm trying to save and load buildings on my own, i made all the variables like SnappedTo,PlacedOn public and saved a BuildingGroup into a prefab, making sure to fill all the proper variables of each building (SnappedTo,PlacedOn,BuildingGroup..), however i'm having a problem with multiple overlapping sockets staying activated. I saw that default loading uses BuildingGroup.HandleOccupiedSockets method, so i tried calling it myself too, it deactivates some colliders, but still doesnt solve the issue. For comparison i load one buildingGroup with the default uConstruct saving system, and one group with my method, every single variable, public and private (in debug view) is the same between every single building and its components in those groups, but the one loaded with default method doesn't have the problem of me being able to place multiple buildings into a place where multiple sockets would overlap, but mine does have that problem. Spent like 4 days trying to debug this, sorry for the long post, any suggestions? Maybe i missed some variables
     
    ElroyUnity likes this.
  44. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    Can you send me a reproduction project on the mail/pm? Will be happy to help!
     
  45. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    After importing uConstruct from the asset store these are the only things i modified:
    Code (CSharp):
    1. UCCallbacksManager.cs OnApplicationQuit() removed the call to UCSavingManager.Save(); after creating a save file for the first time, because i want to only load the save and discard the playmode changes
    2. BuildingGroupAOITarget.cs added [SerializeField] to buildingGroup
    3. BaseBuilding.cs added [SerializeField] to _placedOn
    4. BaseBuilding.cs added [SerializeField] to _buildingGroup
    then i set values to these variables in the prefab using Editor Debug view



    Mod Edit: DO NOT post public share assets from the asset store. It is a violation of the TOS and just not cool. Contact the author directly via pm to securely share projects/content related to their work.
     
    Last edited by a moderator: Apr 23, 2019
  46. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    There's a reason I asked you to send me the reproduction project on a private message
    instead of sending here the uConstruct code.
     
    Last edited: Apr 23, 2019
  47. dimon_babon

    dimon_babon

    Joined:
    Dec 30, 2018
    Posts:
    25
    Oh sh*t, i'm stupid, was writing the post after a long day and it actually slipped my mind this was a public thread, really sorry!
     
    ElroyUnity likes this.
  48. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    No problem :) Thankfully the mods really helped out
     
  49. thevisad

    thevisad

    Joined:
    Jan 29, 2018
    Posts:
    8
    Howdy, I have run into an issue with using uConstruct with the First Person Controller (Version 2) from Opsive. When applying uConstruct to the same player that the Opsive controller is attached to, the player falls through the terrain. I have been able to replicate this with a new scene, player, importing uConstruct and UFPS and then loading the CubesDemo scene. Setting up the existing player with UFPS will cause the player to drop through the terrain on scene start. Could I get some assistance with this?
     
    Last edited: May 8, 2019
    ElroyUnity likes this.
  50. ElroyUnity

    ElroyUnity

    Joined:
    May 20, 2015
    Posts:
    1,583
    That's strange, did you disable the terrain collider?
    Also - note that uConstruct changes the terrain layer to "BuildingSocket", maybe you need to set it up in the controller settings as a ground?
     
    Tethys and thevisad like this.
unityunity