Adding a Tag to an object from a script

I’m working on a script that changes the ‘tag’ of a game object on collision, but

      // Add the tag "CollidedWithSoloplate" to this object
   this.gameObject.addTag("CollidedWithSoloplate");

   // Log the tagging event at the end
   console.log(`Object "${this.gameObject.name}" has been tagged with 'CollidedWithSoloplate'.`);

this doesn’t seem to be working- am I wrong in assuming this ‘addtag’ method is valid? anyone know of a work around?

Original Post on Discord

by user 962902844049096704

Found a work around@

by user 962902844049096704

Hey :wave:

Where do you import the addTag from?

It seems there isn’t any specific api for tags, you can access the value like this:

this.gameObject.userData["tag"]

https://engine.needle.tools/docs/technical-overview.html#needle-gameobject-data

Please do tell what work-around did you come up with :slight_smile: :cactus:

this.gameObject.userData.tag = 'CollidedWithSoloplate';

That’s exactly what I used :slightly_smiling_face:

by user 962902844049096704

This can be marked as resolved / archived

by user 962902844049096704

Glad you found it! :+1: