Forum begins after the advertisement:
[Part 12] Withering of Plant Problem
Home › Forums › Video Game Tutorial Series › Creating a Farming RPG in Unity › [Part 12] Withering of Plant Problem
- This topic has 8 replies, 2 voices, and was last updated 2 weeks, 4 days ago by
Jonathan Teo.
-
AuthorPosts
-
January 28, 2025 at 2:55 pm #17156::
partpaI encountered a problem regarding the Wither status of the Plant.
Scenario: -I plant, watered and leave the planting area scene -Plant health goes up -Plant health goes down when not watered (Sample 15 Plant Health) -Return to the Planting Area scene -Leave the Planting Area scene -Plant Health is 2,500
View post on imgur.com
January 29, 2025 at 11:07 am #17157::Did the Debug message come from GameStateManager?
- 1 anonymous person
January 29, 2025 at 11:55 pm #17160January 30, 2025 at 11:49 am #17161::The problem happens when you load into the scene. Try adding debug logs on the functions that get called, like
public void ImportCropData(List<CropSaveState> cropDatasetToLoad) { Debug.Log("ImportCropData called"); cropData = cropDatasetToLoad; foreach (CropSaveState cropSave in cropDatasetToLoad) { Debug.Log($"Importing crop - Health: {cropSave.health}"); //... rest of the code ... } }
- 1 anonymous person
January 30, 2025 at 3:03 pm #17165January 30, 2025 at 3:18 pm #17166January 30, 2025 at 3:22 pm #17167::This is my UpdateFarmState
void UpdateFarmState(GameTimeStamp timestamp) { //Updates the Land and Crop Save states as long as the player is outside of the PlantingArea scene if(SceneTransitionManager.Instance.currentLocation != SceneTransitionManager.Location.PlantingArea) { if (SoilManager.urbanFarmData == null) { return; } List<SoilSaveState> soilData = SoilManager.urbanFarmData.Item1; List<CropSaveState> cropData = SoilManager.urbanFarmData.Item2; //If there are no crops planted on a certain soil, don't need to update if(cropData.Count == 0) { return; } for(int i = 0; i < cropData.Count; i++) { CropSaveState crop = cropData[i]; SoilSaveState soil = soilData[crop.soilID]; //Check if the crop is already wilted if(crop.cropState == NewCropBehaviour.CropState.Wilted) { continue; } //Update the Soil's state soil.ClockUpdate(timestamp); //Update the crop's state based on the soil state if(soil.soilStatus == PottingSoil.SoilStatus.Watered) { crop.Grow(); } else if(crop.cropState != NewCropBehaviour.CropState.Seed) { crop.Wither(); } //Update the element in the array cropData[i] = crop; soilData[crop.soilID] = soil; } SoilManager.urbanFarmData.Item2.ForEach((CropSaveState crop) => { Debug.LogWarning(crop.seedToGrow + "\n Health: " + crop.health + "\n Growth: " + crop.growth + "\n State: " + crop.cropState.ToString()); }); } }
February 1, 2025 at 9:28 am #17172::I mean the ImportCropData in LandManager
//Load over the static farmData onto the Instance's cropData public void ImportCropData(List<CropSaveState> cropDatasetToLoad) { cropData = cropDatasetToLoad; foreach (CropSaveState cropSave in cropDatasetToLoad) { Debug.Log($"Importing crop - Health before: {cropSave.health}"); //Access the land Land landToPlant = landPlots[cropSave.landID]; //Spawn the crop CropBehaviour cropToPlant = landToPlant.SpawnCrop(); Debug.Log(cropToPlant.gameObject); //Load in the data SeedData seedToGrow = (SeedData)InventoryManager.Instance.GetItemFromString(cropSave.seedToGrow); cropToPlant.LoadCrop(cropSave.landID, seedToGrow, cropSave.cropState, cropSave.growth, cropSave.health); } }
- 1 anonymous person
February 1, 2025 at 8:07 pm #17173::This is the Result
Might be wondering why the Soil changed to Green, it just turn into Weed state and not watered
View post on imgur.com
February 2, 2025 at 6:07 am #17177::Something is increasing the health in between. Where’s the debug logs from the update farm state? In Visual Studio, right click SoilManager.urbanFarmData.Item2 on “Item2”, select Find all references to it, and check what is being updated. If you can’t find the part of your code that is increasing the value, add a debug log everywhere it is used.
-
AuthorPosts
- You must be logged in to reply to this topic.