Hi all!
My current goal is to electrify a Spinning Wheel. I understand that other plugins with similar features spawn other electrical components (like branches) as children and reposition them to match, but is this the only way? I figured it should also be possible by adding a IOEntity component to the Spinning Wheel.
void OnEntityBuilt(Planner planner, GameObject gameObject)
{
BaseEntity _entity = gameObject?.ToBaseEntity();
if (_entity?.ShortPrefabName != "spinner.wheel.deployed")
return;
BaseEntity _wheelEntity = GameManager.server.CreateEntity(_entity.PrefabName, _entity.transform.position, _entity.transform.rotation);
ElectricSpinningWheel _wheel = _wheelEntity.gameObject.AddComponent<ElectricSpinningWheel>();
NextTick(() => {
_entity.Kill();
_wheel.Spawn();
});
}
class ElectricSpinningWheel : IOEntity
{
BaseEntity Wheel;
public void Awake()
{
this.Wheel = this.GetComponent<BaseEntity>();
this.inputs = new IOEntity.IOSlot[1]{
new IOEntity.IOSlot{
niceName = "Input",
type = IOType.Electric,
handlePosition = Wheel.transform.position,
rootConnectionsOnly = false,
mainPowerSlot = true,
}
};
this.outputs = new IOEntity.IOSlot[0];
}
}Using the above code, I can spawn a wheel in the game that does have the
ElectricSpinningWheel component, but I am getting a console error when doing so: PrefabID is 0! assets/prefabs/deployable/spinner_wheel/spinner.wheel.deployed.prefab. The wheel has no wire socket in the game to connect to.Instead of
CreateEntity, I also tried to use Facepunch.Instantiate.GameObject(GameManager.server.FindPrefab(_entity.PrefabName), _entity.transform.position, _entity.transform.rotation), but that kicked me with a client error: Entities Out Of Order: expected n, received n+1 and produced a NRE in IOEntity.Save() on the server (additional NRE in IOEntity.SendChangedToRootRecursive() when trying to destroy the malfunctioning entity again).What step am I missing? Any help about how to set it up correctly is much appreciated!