playMaker

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

cel

  • Junior Playmaker
  • **
  • Posts: 96
    • View Profile
help with custom action [SOLVED]
« on: June 06, 2019, 10:35:58 AM »
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, 03:22:36 AM by cel »

Deek

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: help with custom action
« Reply #1 on: June 07, 2019, 04: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

  • Junior Playmaker
  • **
  • Posts: 96
    • View Profile
Re: help with custom action (solved)
« Reply #2 on: June 09, 2019, 03:14:36 AM »
brilliant, thanks for your help Deek