缺氧
Customize Plants
Gariba 7 月 19 日 上午 11:37
Crash when modifying fruit amount of Ovagro Vines
So, when changing the fruit amount on the Ovagro Vines, I get a crash when (I think) new vines are revealed in the map:

Exception in: (VineMother).VineMother.root.grown.growingBranches.Enter
System.NullReferenceException: Object reference not set to an instance of an object
at Growing.OnNewGameSpawn (System.Object data) [0x00007] in <3b73c925114143c5bad31ccbc5facdf1>:0
at Growing+<>c.<.cctor>b__39_0 (Growing component, System.Object data) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at EventSystem+IntraObjectHandler`1[ComponentType].Trigger (UnityEngine.GameObject gameObject, System.Object eventData) [0x0001e] in <7becb3f73037484c93dc2b548fe42a58>:0
at EventSystem.Trigger (UnityEngine.GameObject go, System.Int32 hash, System.Object data) [0x0004f] in <7becb3f73037484c93dc2b548fe42a58>:0
at EventExtensions.Trigger (UnityEngine.GameObject go, System.Int32 hash, System.Object data) [0x0001d] in <7becb3f73037484c93dc2b548fe42a58>:0
at VineMother+Instance.AttemptToSpawnBranches () [0x00059] in <3b73c925114143c5bad31ccbc5facdf1>:0
at VineMother.AttemptToSpawnBranches (VineMother+Instance smi) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at VineMother.SpawnBranchesIfNewGameSpawn (VineMother+Instance smi) [0x00008] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].ExecuteActions (StateMachine`4+State[StateMachineType,StateMachineInstanceType,MasterType,DefType] state, System.Collections.Generic.List`1[T] actions) [0x00048] in <3b73c925114143c5bad31ccbc5facdf1>:0

at UnityEngine.Logger.Log (UnityEngine.LogType logType, System.Object message, UnityEngine.Object context) [0x00000] in <82f243aab18c4f32918da2df41974365>:0
at UnityEngine.Debug.LogError (System.Object message, UnityEngine.Object context) [0x00000] in <82f243aab18c4f32918da2df41974365>:0
at Debug.LogError (System.Object obj, UnityEngine.Object context) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at DebugUtil.LogErrorArgs (UnityEngine.Object context, System.Object[] objs) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at DebugUtil.LogException (UnityEngine.Object context, System.String errorMessage, System.Exception e) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].ExecuteActions (StateMachine`4+State[StateMachineType,StateMachineInstanceType,MasterType,DefType] state, System.Collections.Generic.List`1[T] actions) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].PushState (StateMachine+BaseState state) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].GoTo (StateMachine+BaseState base_state) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+Parameter`1+Transition[StateMachineType,StateMachineInstanceType,MasterType,DefType,ParameterType].Evaluate (StateMachine+Instance smi) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].TryEvaluateTransitions (StateMachine+BaseState state, System.Int32 goto_id) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].PushState (StateMachine+BaseState state) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].GoTo (StateMachine+BaseState base_state) [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine+Instance.StartSM () [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachine`4+GenericInstance[StateMachineType,StateMachineInstanceType,MasterType,DefType].StartSM () [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at StateMachineController.StartSMIS () [0x00000] in <3b73c925114143c5bad31ccbc5facdf1>:0
at KPrefabID.OnSpawn () [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at KMonoBehaviour.Spawn () [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at Util.SpawnComponent (UnityEngine.Component cmp) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at MyAttributeManager`1[T].OnStart (System.Object obj, KMonoBehaviour cmp) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at MyAttributes.OnStart (System.Object obj, KMonoBehaviour cmp) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at MyAttributes.OnStart (KMonoBehaviour c) [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at KMonoBehaviour.Spawn () [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
at KMonoBehaviour.Start () [0x00000] in <7becb3f73037484c93dc2b548fe42a58>:0
Build: U56-679336-SCRPD
< >
正在显示第 1 - 14 条,共 14 条留言
Fumihiko  [开发者] 7 月 19 日 下午 11:31 
Possible you set an invalid id. The game does not like it, if you spawn a null object.
Gariba 7 月 20 日 上午 9:35 
It doesn't crash if I apply the setting for an existing save. It seems to me it crashes whenever a new instance of the plant is initialized (eg. through revealing new parts of the map, enabling dev mode included). Changing other parameters of VineBranch like temperature and pressure ranges causes no issues at all. Could it be that it's trying to apply the setting to a growing vine, which does not yet give fruit, therefore trying to modify a null object?
Gariba 7 月 21 日 上午 6:52 
May I suggest adding a check to skip modifying values if they are invalid or null to avoid the crash?
Fumihiko  [开发者] 7 月 21 日 上午 9:41 
I looked up the plant. No wonder that does not work. That's a whole new mechanic. When you set a fruitId (or amount) it will patch the plant to give it the growth components (so decorative plants can have fruits).
This plant clearly has incompatible components that will conflict with that. There is no solution for that. If I were to patch this, I would need to remove the new mechanic, which is probably undesireable.
Fumihiko  [开发者] 7 月 21 日 上午 9:44 
Although if the plant grows fruits through a different mechanic, I could check that and edit that instead. But that's a sizable rewrite.
Gariba 7 月 22 日 上午 9:37 
After some trial and error, I (well, ChatGPT mostly) finally found a patch that actually works to change the fruit yield. Here's the code I used:
using HarmonyLib; using System; using System.Collections.Generic; using System.Linq; using TUNING; using UnityEngine; namespace Quadovagro { public class QuadovagroPatches { [HarmonyPatch(typeof(Db), nameof(Db.Initialize))] public class Db_Initialize_Patch { public static void Postfix() { for (int i = 0; i < CROPS.CROP_TYPES.Count; i++) { var crop = CROPS.CROP_TYPES;
if (crop.cropId == VineFruitConfig.ID)
{
CROPS.CROP_TYPES = new Crop.CropVal(VineFruitConfig.ID, crop.cropDuration, 4);
Debug.Log($"[Quadovagro] Updated VineFruit crop yield to 4 units.");
break;
}
}
}
}
}
}[/code]
Fumihiko  [开发者] 7 月 23 日 上午 7:42 
How do you know it works? It seems weird to me that you can setup all the environment, but then also require an LLM to generate code.

Btw, there are at least two errors in this snipplet. CROPS_TYPES is a list, but it sets a Crop.CropVal instead. So there is the indexer missing.

Another problem is that Crop.CropVal has a completely different constructor.

But the code does look convincing. Which is a major problem. I absolutely hate LLMs. I am not exaggerating, I really mean that.
Gariba 7 月 23 日 上午 11:51 
I'm also not fond of LLMs. But between work, life, and actually wanting to play games, I don't really want to spend time learning to properly code every game I like. I've got enough knowledge to at least know the general direction of what I'm looking for, but that's it.
I imagined the code would like absolutely disgusting to you lol.

As for how I know it works, I tested ingame.
Fumihiko  [开发者] 7 月 24 日 上午 8:03 
I guess there is some fragmentation because of the conflicting markup tags. You can even see the /code tag at the end.
Fumihiko  [开发者] 7 月 24 日 上午 11:02 
I changed the code. It stops applying the components for crops, if the plant already has the Crop component.
Gariba 7 月 24 日 下午 12:09 
When applying a fruit_amount multiplier to the VineBranch after your last update, the codex reflects the changes but the actual harvest is still unchanged.
Fumihiko  [开发者] 7 月 24 日 下午 12:15 
I guess I need to update the traits too.
Fumihiko  [开发者] 8 月 26 日 上午 10:53 
Mh... did I fix this? Let me know, if this is broken.
Gariba 8 月 29 日 下午 1:22 
Just tested it, no crashes and yield is being properly multiplied. Thank you for your awesome work!
Sorry for the delay in responding. I was... otherwise engaged in salvaging derelicts around Ganymede.
< >
正在显示第 1 - 14 条,共 14 条留言
每页显示数: 1530 50