I need to have BuildingBlocks, specifically floors, that are able to be destroyed with normal weapons but later need to be regenerated. How would you go about placing objects? Is there a method to place a BuildingBlock at xyz? I have a List<BuildingBlock> filled with all of the floors needing to be remade.
Solved Regenerative BuildingBlocks
Discussion in 'Rust Development' started by Scarsz, Jun 24, 2016.
-
You can spawn in the prefab using GameManager.server.CreateEntity, although I'm pretty sure if you are saving them to a list that entry will become null once the block is destroyed. You would be better off saving the position and rotation then spawning the prefab back using that data
-
Definitely what I'm looking for but I guess I have a problem with it. This is what I have now
which works but it doesn't show up in game. If I try to build a wall on the exact position that this new prefab was made, the game says "placing through wall." Not sure how I'd fix this. Also, when you walk in the direct center of where the floor should be, if you're not in noclip, you're stuck in place and you teleport up a little, fall, and repeat. Restarting the server gets rid of the entity.Code:GameObject newWall = GameManager.server.CreatePrefab("assets/prefabs/building core/floor/floor.metal.prefab", position, rotation);Last edited by a moderator: Jun 24, 2016 -
Did you spawn it? Try it like this
If you get the BuildingBlock component then you can also change other variables from within the BuildingBlock class prior to spawningCode:BaseEntity block = GameManager.server.CreateEntity("assets/prefabs/building core/floor/floor.metal.prefab", position, rotation); block.Spawn();
Code:BuildingBlock block = build.GetComponent<BuildingBlock>(); if (block != null) { block.grounded = true; block.grade = type; block.health = health; block.Spawn(); //etc } -
Tried it like that, gotChanging it, ended up withCode:
CreateEntity called on a prefab that isn't an entity! assets/prefabs/building core/floor/floor.metal.prefab
which I gotCode:GameObject newWall = GameManager.server.CreatePrefab("assets/prefabs/building core/floor/floor.metal.prefab", wall.transform.position, wall.GetEstimatedWorldRotation()); newWall.Spawn();Code:error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `Spawn' and no extension method `Spawn' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?
Last edited by a moderator: Jun 24, 2016 -
There is no spawn method in GameObject, I'm not sure why you can't spawn that in using the code above though, must be a different prefab path that is actually required.
-
Yep, I guess you just can't make the metal prefab itself, have to use /floor.prefab.
Code ended up being this for anyone with the same question
which ends up being perfect for my situation; entity has 0 health so whenever literally anything damages it (at any grade) it's destroyed. Thanks a bunch @Shady757 @k1lly0uCode:BaseEntity newBlock = GameManager.server.CreateEntity("assets/prefabs/building core/floor/floor.prefab", position, rotation); newBlock.Spawn(); BuildingBlock newBlockProperties = newBlock.GetComponent<BuildingBlock>(); //newBlockProperties.health = 750; //newBlockProperties.SetGrade(BuildingGrade.Enum.Stone);
