First, thanks for the plugin, it's really good at what it does, simple to use, and easily editable.
Now, to the core of the issue...
I am trying to spawn sets of splines using prefabs.
I noticed that CurvyConnections are always contained within the CurvyGlobalManager.
My issue is that I do not have access to it in prefab mode.
This means that any CurvyConnection I create while inside my prefab will be lost the second I exit it.
Connections are stored in objects children to the _CurvyGlobal_ gameObject. That gameObject is automatically created by some Curvy scripts, and stores data shared between various scripts, like pools. So to store connections in a prefab, you need to have in the same prefab both your splines and the _CurvyGlobal_. The issue with that is that, supposing that you want to instantiate the prefab twice, you will end up with two _CurvyGlobal_ objects, and that's bad. Curvy, when detecting that multiple _CurvyGlobal_ objects are on the same scene, will merge them into only one. That process means deleting the other _CurvyGlobal_ objects. The problem with recent Unity versions is that scripts can't delete objets in prefabs without a user input. So you will end up having error messages like "InvalidOperationException: Destroying a GameObject inside a Prefab instance is not allowed". You will then have to manually get rid of all the _CurvyGlobal_objects except one.
What I described here is far from perfect, I agree. I will work at some point on getting connections out of _CurvyGlobal_ to solve this issue. It is on my todo list.
Is my solution ok for you as a workaround?
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Problem is, I am unable to place a CurvyGlobalManager onto a gameobject inside my prefab, it simply deletes itself instantly.
Or maybe it becomes HideInHierarchy? I'm not too sure.
Keep in mind that only one CurvyGlobalManager is allowed in a scene. So if you are trying to add a second one it will get deleted.
I attached a prefab that contains 2 connected splines. Use it in an empty scene to see how it is made.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
06-12-2020, 08:31 AM (This post was last modified: 06-14-2020, 07:06 PM by CoolUser.)
Yes, I understand that only one is allowed in a scene.
I was talking about adding one directly into a prefab.
Seems like your gameobject has one inside, I just can't see it unless I put the prefab in a scene.
I suppose it has to do with HideInHierarchy.
I do understand what you're getting at about deleting the manager from prefabs in scene mode though, the errors make sense.
Would be sweet to see a version independent from the global manager down the line.
For now I decided to make my own hooks inside the Add and Remove methods in Connection.
That way I can create my connections when the game starts (From metadata I saved with my hooks), since the ones I use are always the same.
I am not sure if this is the right thread for this but I am facing a very similar issue - all the connections in the prefab throw the "Destroying a Prefab" error as mentioned earlier. If it is, has there been any updates since that would help me with this?
10-02-2024, 06:41 PM (This post was last modified: 10-02-2024, 06:43 PM by _Aka_.)
Hi,
Changes were made since, which allows for easier workarounds:
Create in a scene your splines and connect them
Create an empty gameobject
Move to it all your splines and the related connections
Make a prefab from it.
By "the related connections" I mean the gameobjects named "Connection" that are children of _CurvyGlobal_ . They store the connection information regarding your splines.
With this solution, you can create prefabs and use them without issues.
I attached an example prefab.
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.