Teleporting a Trail Effect in Unity2D


A month ago I found myself on r/Unity2D on Reddit asking about something that seems like a very specific issue. 

What happened?

I had the Reacción ship's trail make this path revealing line on teleports. You know, my code indeed moved the ship from the lower right to the little teleport on the top left, but I think that teleportations and trails should have nothing to do with each other. I tried setting every Trail Renderer object variable as false and then true after telepoort, even with its GameObject and everything. 

Ironically, to this day, I didn't get any answer on Reddit... And we live in a weird time in technology nowadays, so I specified briefly this situation to Google Gemini's AI and, as a developer I hate to say it, but the solution came there, after not finding this issue on Google itself.  I hope this devlog post, or my Reddit thread starts to come up sooner or later. Regarding the solution, I should've had thought it myself, not gonna lie. Maybe I was to lazy to consider it an option since it's a little bit messy. 

How to prevent this?

In short, you should treat the trail as the disposable set of particles it is. Make it a Prefab. Upon a teleport "A", detach the trail (TrailRenderer) from the parent GameObject (in this case, Reacción's ship), teleport to "B", then instantiate it below the parent game object, nest it as a child and set its local coordinates to 0. This moment is were you should set the original trail as a variable in your parent gameobject to the new nest. If not, how would you detach it in a future teleport? (See the "after" screenshot, there are two teleports in it).

The original trail remains there until it's shut. That's how I like it. But you got many ways to delete it if you rather do that (Destroy).

What I learned

I think I should give more credit to instantiating prefabs, detaching and destroying. I'm a little bit lazy in terms of nesting manually in the editor, but probably code is the way to go.

Files

Reacción Web 0.7.5.zip Play in browser
18 days ago

Leave a comment

Log in with itch.io to leave a comment.