19-08-2021, 09:57 AM
(This post was last modified: 19-08-2021, 10:08 AM by fishing-rod.)
Hi, I ran into a problem assigning and removing the targets of particle attachments at runtime.
I'm on Obi Rope 6.2 and Unity 2020.3.15f2.
I think I got it to work at some point, but I cant figure out the build in my collab history.
Whenever I attach something to the rope, i.e. setting the target property, I run this code so that everything sits at the right position:
I have a breakpoint at ResetParticles and the funktion is properly executed. The attached GameObjects (hook and equipment) are at their original positions when I pause the editor.
The rope particles are not though. I also still see the target properties being set in the inspector.
The screenshot is during the pause from code. The two red dots are the attached GameObjects, the line goes right through them in its original state.
There is some manual workaround which makes it work: When I de- and reactivate the ObiRope component during the pause and then resume,
the particles are back at their original positions. Recreating that in code with Rod.line.gameObject.SetActive() doesn't work though.
Am I approaching this in the wrong way?
I'm on Obi Rope 6.2 and Unity 2020.3.15f2.
I think I got it to work at some point, but I cant figure out the build in my collab history.
Whenever I attach something to the rope, i.e. setting the target property, I run this code so that everything sits at the right position:
Code:
/// <summary>
/// 1. Temporary saves the targets of the obi particles attachments.
/// 2. Sets the targets to null.
/// 3. Resets all line particles.
/// 4. Sets attachments to their original positions.
/// 5. Reassigns the targets to the attachments.
/// </summary>
public void ResetLine()
{
// 1 In order to reset particles all attachment targets have to be removed.
ObiParticleAttachment[] attachments = Rod.lineObj.GetComponents<ObiParticleAttachment>();
Transform[] formerTargets = new Transform[attachments.Length];
ObiRope rope = Rod.lineObj.GetComponent<ObiRope>();
// 2
for (int i = 0; i < attachments.Length; i++)
{
formerTargets[i] = attachments[i].target;
attachments[i].target = null;
}
// 3
rope.ResetParticles();
// 4
if (attachedHook != null)
{
attachedHook.transform.position = Rod.hookObj.transform.position;
}
if (attachedEquipment != null)
{
attachedEquipment.transform.position = Rod.equipObj.transform.position;
}
// Pause for debugging purposes
EditorApplication.isPaused = true;
// 5
for (int i = 0; i < attachments.Length; i++)
{
attachments[i].target = formerTargets[i];
}
}
I have a breakpoint at ResetParticles and the funktion is properly executed. The attached GameObjects (hook and equipment) are at their original positions when I pause the editor.
The rope particles are not though. I also still see the target properties being set in the inspector.
The screenshot is during the pause from code. The two red dots are the attached GameObjects, the line goes right through them in its original state.
There is some manual workaround which makes it work: When I de- and reactivate the ObiRope component during the pause and then resume,
the particles are back at their original positions. Recreating that in code with Rod.line.gameObject.SetActive() doesn't work though.
Am I approaching this in the wrong way?