Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinated spawn system fails to spawns a custom prefab created using CloneTemplate with the "classIdToClone" overload #497

Closed
mroshaw opened this issue Nov 13, 2023 · 1 comment · Fixed by #498
Assignees

Comments

@mroshaw
Copy link

mroshaw commented Nov 13, 2023

Describe the bug
If a custom prefab is created using the CloneTemplate "classIdToClone" overload, then attempts by the coordinated spawn system to spawn instances of that prefab fail with the following error:

[Error  : Unity Log] ArgumentException: The Object you want to instantiate is null.
Stack trace:
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.Boolean awake) (at <bd0d47c27bd84106afaaecc2c74cdb94>:0)
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Transform parent, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.Boolean awake) (at <bd0d47c27bd84106afaaecc2c74cdb94>:0)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Transform parent, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.Boolean awake) (at <bd0d47c27bd84106afaaecc2c74cdb94>:0)
EditorModifications.Instantiate[T] (T prefab, UnityEngine.Transform parent, UnityEngine.Vector3 localPos, UnityEngine.Quaternion localRot, System.Boolean awake) (at <2e7ba6396c044f81892034b200fcf2b6>:0)
UWE.Utils.InstantiateDeactivated (UnityEngine.GameObject prefab, UnityEngine.Vector3 localPosition, UnityEngine.Quaternion localRotation) (at <aafb86ac724b47ddb09cd2e6deee2370>:0)
Nautilus.MonoBehaviours.EntitySpawner+<SpawnAsync>d__2.MoveNext () (at <8d4c2e0e0bd24722a886b4a7f33a268e>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <bd0d47c27bd84106afaaecc2c74cdb94>:0)

To Reproduce
Steps to reproduce the behavior:

Create a custom prefab, using the "classIdToClone" overload:

private const string PrefabClassId = "PetFabricatorFragment";

public static PrefabInfo Info { get; } = PrefabInfo
   .WithTechType(PrefabClassId, null, null, unlockAtStart: false);

CustomPrefab fabricatorFragmentPrefab = new CustomPrefab(Info);

PrefabTemplate cloneTemplate = new CloneTemplate(fabricatorFragmentPrefab.Info, "8029a9ce-ab75-46d0-a8ab-63138f6f83e4");
fabricatorFragmentPrefab.SetGameObject(cloneTemplate);
fabricatorFragmentPrefab.SetSpawns(new SpawnLocation(new Vector3(-172.27f,-43.07f, -234.29f), new Vector3(346.22f, 345.14f, 8.72f)));
fabricatorFragmentPrefab.Register();

Run the game and open the BepInEx log, "LogOutput.log".
Observe the error text.
Back in the game, open the console and warp to the spawn location: warp -172.27 -43.07 -234.29
Observe that the prefab has not spawned in the location.
In the console, manually spawn the prefab instance: spawn PetFabricatorFragment 1
Note that the prefab instance spawns successfully.

Expected behavior
The prefab instance should be spawned in the given location automatically, without errors.

Screenshots
If applicable, add screenshots to help explain your problem.

@Metious Metious self-assigned this Nov 14, 2023
@Metious
Copy link
Member

Metious commented Nov 14, 2023

This is because of the single-request prefabs we added recently and the fact that we didn't modify the logic to address yielding the same request instance more than once.

I will take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants