{"id":1856,"date":"2022-08-01T15:51:41","date_gmt":"2022-08-01T15:51:41","guid":{"rendered":"https:\/\/golemitegames.com\/?post_type=docs&#038;p=1856"},"modified":"2022-08-02T18:50:19","modified_gmt":"2022-08-02T18:50:19","password":"","slug":"objectplacer-2","status":"publish","type":"docs","link":"https:\/\/golemitegames.com\/index.php\/docs\/objectplacer-2\/","title":{"rendered":"ObjectPlacer"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public GameObject PlaceObject(GameObject obj, GridObject.Data gridObjectData, int layer)<\/strong><\/h2>\n\n\n\n<p>Uses all of the data passed from the <strong>GridSelector<\/strong> to place an object on the grid.<\/p>\n\n\n\n<p>This function is primarily used by the <strong>GridSelector<\/strong> and currently the class <strong>GridObject.Data<\/strong> is very tricky to replicate the relevant information publicly. <\/p>\n\n\n\n<p>If your goal is to place objects with a single cell size only, you could potentially use the below overloaded version of this method. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void PlaceObject(GameObject obj,<\/strong> <strong>Vector3 placePos,<\/strong> <strong>GridSquare grid,<\/strong> <strong>int layer)<\/strong><\/h2>\n\n\n\n<p>This function places the object on the grid and changes the layer back to the original layer the object was on. You will need the obj, its position to place it, the grid to change the cell status and the object&#8217;s original layer. <\/p>\n\n\n\n<p>It also adds the GridObject script to it, to keep a reference to the grid it is on.<\/p>\n\n\n\n<p class=\"has-background-color has-text-color\">Note &#8211; This overloaded version of <strong>PlaceObject<\/strong> only supports placing objects a single cell big and is also not added to the <strong>ObjectStorage<\/strong>.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Places an obj on left mouse click\nObjectPlacer objectPlacer;\nGridSquare grid;\npublic GameObject myObject;\n\nvoid Update()\n{\n    if (Input.GetMouseButton(0)) \n    {\n        objectPlacer.PlaceObject(myObject, posToPlace, grid, myObject.layer)\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public GameObject DelayBuildStart(GameObject obj, GridObject.Data gridObjectData, int layer, int buildTime)<\/strong><\/h2>\n\n\n\n<p>Uses all of the data passed from the <strong>GridSelector<\/strong> to place a temperory timed object on the grid. This only works if the time set in the <strong>SelectObject<\/strong> button is more than <strong>0<\/strong>. <\/p>\n\n\n\n<p>This function is primarily used by the <strong>GridSelector<\/strong> and currently the class <strong>GridObject.Data<\/strong> is very tricky to replicate the relevant information publicly. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void MoveObject(GameObject obj, GridObject.Data gridObjectData, int layer)<\/strong><\/h2>\n\n\n\n<p>Uses all of the data passed from the <strong>GridSelector<\/strong> to move an object on the grid.<\/p>\n\n\n\n<p>This function is primarily used by the <strong>GridSelector<\/strong> and currently the class <strong>GridObject.Data<\/strong> is very tricky to replicate the relevant information publicly. <\/p>\n\n\n\n<p>If you would like to move objects to a particular position on the grid, consider using the below version of <strong>MoveObject<\/strong>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void MoveObject(GameObject obj, Vector3 pos, GridSquare grid, int layer)<\/strong><\/h2>\n\n\n\n<p>Moves the given <strong>obj<\/strong> to position <strong>pos<\/strong> on <strong>grid<\/strong>. It will also place the given <strong>layer<\/strong> on it and its children. <\/p>\n\n\n\n<p>Please note that when moving an object, you are only moving it visually. To move it on the system as well you will need to call <strong>BlockCells<\/strong>. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>ObjectPlacer objectPlacer;\nGridSquare grid;\npublic GameObject myObject;\npublic GameObject placedObj;\n\n\/\/Moves the placed object if its position matches your current objects pos\nvoid Update()\n{\n    if (myObject.transorm.position == placedObj.transform.position) \n    {\n        objectPlacer.MoveObject(placedObj, posToMoveTo, grid, myObject.layer)\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public List GetSpecificCheckPositions(Vector3[] checkPositions, SelectObject.ObjectSize objectSize)<\/strong><\/h2>\n\n\n\n<p>This function returns a <strong>List&lt;Vector3&gt;<\/strong> of the objects check positions that actually need blocking. <\/p>\n\n\n\n<p>From the <strong>GridSelector<\/strong> there is an array called <strong>gridCheckPositions<\/strong> for all current check positions of up to 5&#215;5 grid. There is also the <strong>SelectObject.ObjectSize<\/strong> which holds that objects physical size. Because we only want to block that objects size on those particular check positions, this function sorts and returns that <strong>List<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void BlockCells(List checkPositions, GameObject obj, GridSquare grid)<\/strong><\/h2>\n\n\n\n<p>Given an array of <strong>checkPositions<\/strong> to block, loops through them all, and changes that <strong>grid<\/strong> cell&#8217;s status to be marked with the given<strong> obj<\/strong>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void HidePlacedObjCells(GridSquare gridSquare,  List checkPositions)<\/strong><\/h2>\n\n\n\n<p>Hides the given <strong>checkPositions<\/strong> cells on <strong>gridSquare<\/strong>.<\/p>\n\n\n\n<p>This method does not work for grid types Simple, Points or Lines. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void ShowRemovedObjCells(GridSquare gridSquare,  List checkPositions)<\/strong><\/h2>\n\n\n\n<p>Shows the given <strong>checkPositions<\/strong> cells on <strong>gridSquare<\/strong>.<\/p>\n\n\n\n<p>This method does not work for grid types Simple, Points or Lines. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public float GetObjectHeight(GameObject obj)<\/strong><\/h2>\n\n\n\n<p>Given an <strong>obj<\/strong> returns the objects height based on its collider. <\/p>\n\n\n\n<p>This method is mostly used to decide whereabouts a UI element should appear above the object. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>public GameObject PlaceObject(GameObject obj, GridObject.Data gridObjectData, int layer) Uses all of the data passed from the GridSelector to place an object on the grid. This function is primarily used by the GridSelector and currently the class GridObject.Data is very tricky to replicate the relevant information publicly. If your goal is to place objects with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"doc_category":[45],"doc_tag":[],"class_list":["post-1856","docs","type-docs","status-publish","hentry","doc_category-scripting-gridbuilder2"],"acf":[],"aioseo_notices":[],"year_month":"2026-04","word_count":622,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"rickitz5h","author_nicename":"rickitz5h","author_url":"https:\/\/golemitegames.com\/index.php\/author\/rickitz5h\/"},"doc_category_info":[{"term_name":"Scripting","term_url":"https:\/\/golemitegames.com\/index.php\/docs-category\/scripting-gridbuilder2\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":24,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1856\/revisions"}],"predecessor-version":[{"id":1883,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1856\/revisions\/1883"}],"wp:attachment":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_category?post=1856"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_tag?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}