Touch/Untouch Problems!

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

aardvarkk

New Member
May 7, 2004
64
0
0
I'm trying to solve this bug I'm having that I just can't wrap my head around...
The code is as follows:
Code:
function Touch()
{
            // destroy all existing potential scores
            foreach AllActors(class'PotentialScore',PotScore)
            {
                PotScore.Destroy();
            }
        
            // only spawn a new potential score if no others exist...
            {
                Spawn(class'PotentialScore',Self);
                log("I just spawned a PotentialScore");
            }
}

Basically, I'm trying to make sure that I only generate a PotentialScore object when no others currently exist. Theoretically, there shoud never be two in existence using this code, but somehow two get spawned. I thought maybe it had something to do with the Destroy() function not destroying the object right away, so I tried creating a boolean called FoundOthers which would only let the object spawn if FoundOthers was false. Still no dice!

I don't understand why the Touch function gets called so often. The problem seems to be one of timing, for sure. It would be much easier if there was a function that got called as soon as two objects touched, and never again. Then, the other function would be called when they were no longer colliding.

It also seems to me that UnTouch is being called while the two objects are still colliding? How is that possible? Touch AND Untouch seem to both be called as one object travels through the other... huh???

Are there any suggestions? Any help would be appreciated, thanks.
 
Last edited:

aardvarkk

New Member
May 7, 2004
64
0
0
Thanks a lot! I hacked together a different solution in the meantime by making another class, but this will definitely come in handy later. Thanks again.