Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
I need to reset the particles to their initial state after e.g. AR tracking is lost.
If I call "ObiSoftbody.ResetParticles", nothing happens.
How can I achieve this?
Thanks!
Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
Still no success, despite trying for hours with GPT-4's help. No matter what I do, the softbody ignores any attempts to change its position/particles on runtime via script.
PLEASE help <3
Love
Felix
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
23-06-2023, 02:19 PM
(This post was last modified: 23-06-2023, 04:03 PM by josemendez.)
(23-06-2023, 11:17 AM)swancollective Wrote: If I call "ObiSoftbody.ResetParticles", nothing happens.
Hi Felix,
ResetParticles() will reset particle positions and orientations (as well as linear/angular velocities) to the values contained in the blueprint, while keeping the softbody transform intact. I just tested with a softbody and it works fine. Keep in mind that it resets particles and particles only -as the name implies- and will not reset the object's transform nor constraints.
You can teleport the softbody to a new position/rotation using softbody.Teleport(pos, rot), which you can combine with ResetParticles(). For example:
Code: using UnityEngine;
using Obi;
public class ResetActor : MonoBehaviour
{
public ObiSoftbody softbody;
public Transform tfrm;
void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
softbody.ResetParticles();
softbody.Teleport(tfrm.position, tfrm.rotation);
}
}
}
(23-06-2023, 11:17 AM)swancollective Wrote: Still no success, despite trying for hours with GPT-4's help. No matter what I do, the softbody ignores any attempts to change its position/particles on runtime via script.
PLEASE help <3
Love
Felix
The manual contains an in-depth explanation of how to manipulate any per-particle properties. See:
http://obi.virtualmethodstudio.com/manua...icles.html
Reading an writing particle positions/orientations works fine as far as I can tell, it is just a matter of accessing the solver.positions and solver.orientations array. What have you tried so far? Can you share your code so that we can take a look?
kind regards,
Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
23-06-2023, 06:00 PM
(This post was last modified: 23-06-2023, 06:36 PM by swancollective.)
Thank you so much for the quick reply and your code - it seems to work! BUT! Only thing, since adding the script, Unity editor keeps crashing on me, also it crashed during build. After that the build succeeded, but the app crashed on my phone. I troubleshot it multiple times and this behavior only happens when this script is present. Maybe any clue why this could be?
As to your question, this is GPT-4s best attempt of resetting the softbody (which also didn't work, after hours of iterating):
Code: using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSoftbody))]
public class ResetObiSoftbody : MonoBehaviour {
ObiSoftbody softbody;
Vector4[] originalPositions;
void Awake(){
softbody = GetComponent<ObiSoftbody>();
originalPositions = new Vector4[softbody.solverIndices.Length];
// Store the original positions
for (int i = 0; i < softbody.solverIndices.Length; ++i){
int solverIndex = softbody.solverIndices[i];
originalPositions[i] = softbody.solver.positions[solverIndex];
}
}
public void ResetToOriginalPosition(){
// Reset the positions
for (int i = 0; i < softbody.solverIndices.Length; ++i){
int solverIndex = softbody.solverIndices[i];
softbody.solver.positions[solverIndex] = originalPositions[i];
}
}
}
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
23-06-2023, 06:42 PM
(This post was last modified: 23-06-2023, 06:47 PM by josemendez.)
(23-06-2023, 06:00 PM)swancollective Wrote: Thank you so much for the quick reply and your code - IT WORKS!!
Only thing, since adding the script, Unity editor keeps crashing on me. Maybe weird coincidence, but it's the only thing I changed, and it never crashed before. Maybe any clue why this could be?
The code above simply iterates trough a couple arrays setting values internally, there's no reason I can think for it to crash. Could you share your editor log, so that I may see the crash stack trace?
(23-06-2023, 06:00 PM)swancollective Wrote: As to your question, this is GPT-4s best attempt of resetting the softbody (which also didn't work, after hours of iterating):
The most likely outcome of that script is a NullRefException at runtime. It doesn't check whether the blueprint is loaded into a solver and simply assumes it to be by the time Awake() is called - which is often not the case, hence causing a null ref when it tries to access the length of the solverIndices. It also omits particle velocities and orientations which should also be reset for the softbody to correctly go back to its initial state, and assumes the solver is at the scene origin.
Here's the closest correct version of it (still assuming the solver is at the origin) even then it's far more verbose and complex than it needs to be - ResetParticles() and Teleport() do a better job in just two lines.
Code: using UnityEngine;
using Obi;
[RequireComponent(typeof(ObiSoftbody))]
public class ResetSoftbody : MonoBehaviour
{
ObiSoftbody softbody;
Vector4[] originalPositions;
Quaternion[] originalOrientations;
void OnEnable()
{
softbody = GetComponent<ObiSoftbody>();
softbody.OnBlueprintLoaded += Softbody_OnBlueprintLoaded;
if (softbody.isLoaded)
Softbody_OnBlueprintLoaded(softbody, softbody.softbodyBlueprint);
}
void OnDisable()
{
softbody.OnBlueprintLoaded -= Softbody_OnBlueprintLoaded;
}
private void Softbody_OnBlueprintLoaded(ObiActor actor, ObiActorBlueprint blueprint)
{
originalPositions = new Vector4[softbody.solverIndices.count];
originalOrientations = new Quaternion[softbody.solverIndices.count];
for (int i = 0; i < softbody.solverIndices.count; ++i)
{
int solverIndex = softbody.solverIndices[i];
originalPositions[i] = softbody.solver.positions[solverIndex];
originalOrientations[i] = softbody.solver.orientations[solverIndex];
}
}
public void ResetToOriginalPosition()
{
for (int i = 0; i < softbody.solverIndices.count; ++i)
{
int solverIndex = softbody.solverIndices[i];
softbody.solver.positions[solverIndex] = originalPositions[i];
softbody.solver.orientations[solverIndex] = originalOrientations[i];
softbody.solver.velocities[solverIndex] = softbody.solver.angularVelocities[solverIndex] = Vector4.zero;
}
}
}
Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
Thank you so much for your reply. So I spent a few more hours debugging, and it consistently crashes the editor, when I use the teleport function.
This is so weird. When I don't teleport, everything runs fine, but as soon as I teleport (which is in fact working), it crashes once I exit play mode.
GPT-4 analyzed my crash report like this - don't know if this is helpful at all:
"The crash report appears to indicate a SIGSEGV (segmentation fault) error which is a specific kind of error caused by accessing memory that "does not belong to you." It's a mechanism that prevents you from corrupting the memory and introducing hard-to-debug memory bugs. Essentially, whenever you get a segmentation fault, you know you are doing something wrong with memory - such as accessing a variable that has already been freed or writing to a read-only portion of memory. The operating system kills the process for this.
From the stack trace, the crash seems to occur during the cleanup of some memory pointers (DelayedPointerDeletionManager::CleanupPendingMainThreadPointers), but it's difficult to say what exactly is the cause just from this. It could be an issue with Unity's memory management, a problem in the Vuforia AR platform, or a bug in your code."
Is there any other way to move a softbody back to its original position without using teleport? It could also destroy and reinitialize the softbody at the original position, maybe? Just don't know how to do that.
Weird, weird, but thanks for your help!!!!
(To clarify: All I try to create is a maze, where you can drag an OBI softbody through - with the option to reset the softbody to its starting point)
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
24-06-2023, 02:48 PM
(This post was last modified: 24-06-2023, 02:58 PM by josemendez.)
(24-06-2023, 11:52 AM)swancollective Wrote: Thank you so much for your reply. So I spent a few more hours debugging, and it consistently crashes the editor, when I use the teleport function.
This is so weird. When I don't teleport, everything runs fine, but as soon as I teleport (which is in fact working), it crashes once I exit play mode.
GPT-4 analyzed my crash report like this - don't know if this is helpful at all:
"The crash report appears to indicate a SIGSEGV (segmentation fault) error which is a specific kind of error caused by accessing memory that "does not belong to you." It's a mechanism that prevents you from corrupting the memory and introducing hard-to-debug memory bugs. Essentially, whenever you get a segmentation fault, you know you are doing something wrong with memory - such as accessing a variable that has already been freed or writing to a read-only portion of memory. The operating system kills the process for this.
From the stack trace, the crash seems to occur during the cleanup of some memory pointers (DelayedPointerDeletionManager::CleanupPendingMainThreadPointers), but it's difficult to say what exactly is the cause just from this. It could be an issue with Unity's memory management, a problem in the Vuforia AR platform, or a bug in your code."
That’s a textbook description of what a segmentation fault is, along with a rather unhelpful analysis of the last call in the stack trace - kinda like saying “this 4-wheeled vehicle could be a car but could also be any other 4-wheeled vehicle“. Nothing too useful.
I’d need the full stack trace, which is contained in the crash log/report. This is essentially a record of the last steps Unity took before crashing. If you could share that it would be great There’s a pretty good chance this has nothing to do with Obi though, since A) it crashes at a point internal to Unity, not Obi and B) teleporting actors is very basic functionality that’s been tried and tested for many years, in many different situations.
(24-06-2023, 11:52 AM)swancollective Wrote: Is there any other way to move a softbody back to its original position without using teleport? It could also destroy and reinitialize the softbody at the original position, maybe? Just don't know how to do that.
Yes, the code I shared in my previous post should do that, provided you store the initial position of the transform.
let me know if I can be of further help!
kind regards,
Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
Thank you for your patience!
I think I figured out the problem, and it didn't have to do with OBI. At the same time of adding your script I deleted a game object, which led to an empty list in another script. I think and hope, that this was the bug. So sorry for the confusion, but the error didn't show up in my console. I just wish AI would be deeply implemented in programs like Unity, able to understand and debug the entire project.
Have a great Sunday!
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
25-06-2023, 11:06 AM
(This post was last modified: 25-06-2023, 11:08 AM by josemendez.)
(25-06-2023, 10:15 AM)swancollective Wrote: Thank you for your patience!
I think I figured out the problem, and it didn't have to do with OBI. At the same time of adding your script I deleted a game object, which led to an empty list in another script. I think and hope, that this was the bug. So sorry for the confusion, but the error didn't show up in my console. I just wish AI would be deeply implemented in programs like Unity, able to understand and debug the entire project.
Have a great Sunday!
You’re welcome!
If you want my two cents, in their current state LLMs are only useful for figuring out syntax and putting together boilerplate code. Semantically speaking the code they generate is extremely low quality, since their logic capabilities are rather poor. AI generated code usually compiles, but it’s full of subtle bugs and you’ll end up spending a lot more time fixing their code than you would writing it yourself.
Cheers,
Posts: 11
Threads: 3
Joined: May 2023
Reputation:
0
You're probably right, but as an artist who only knows how to read a bit of code, it's a tremendous help. I'm sure this will improve a lot in the coming months. But of course I get your point
|