playMaker

Author Topic: help with custom action [SOLVED]  (Read 1137 times)

cel

  • Full Member
  • ***
  • Posts: 132
help with custom action [SOLVED]
« on: June 06, 2019, 01:35:58 PM »
I copied the action create advanced code in order to create primitives, it works but, when i change the spawn position (x=2,y=0,z=0) it creates two primitives. Could someone have a look at the attachment and find out what is going on wrong?
« Last Edit: June 09, 2019, 06:22:36 AM by cel »

Deek

  • Full Member
  • ***
  • Posts: 133
Re: help with custom action
« Reply #1 on: June 07, 2019, 07:29:49 PM »
The problem is that "GameObject.CreatePrimitive()" already creates an instance of the given primitive type and as you later instantiate a new GameObject you end up with two new objects, regardless of the specified position (you likely just noticed because they weren't overlapping anymore).

The solution is to use the reference to the created primitive (the variable "go") instead of instantiating a it a second time.

I've added the fixed script to the attachments and took some liberties with the naming and improved the formatting, as well as adding comments to make it more clear what's going on.
You might compare the two versions to better understand what was causing that behavior.

cel

  • Full Member
  • ***
  • Posts: 132
Re: help with custom action (solved)
« Reply #2 on: June 09, 2019, 06:14:36 AM »
brilliant, thanks for your help Deek