Jump to content
imGua

[FIXED] mesh filter + spawn

Recommended Posts

Try using the ProBuilder.Instantiate() method instead of the regular GameObject.Instantiate code.  PB needs to run some additional functions on spawning in order to generate the mesh correctly.

Share this post


Link to post
Share on other sites

Speaking with another user on this right now, and will be creating a video tutorial specifically for this. I know it's an "unknown" for most people, and we need to make it more obvious somehow.

 

@Karl- maybe we could even force a warning to the console, anytime a PBO is instantiated incorrectly?

Share this post


Link to post
Share on other sites

I was caught out by this as well. I bought ProCore Complete today. My current project relies heavily on dynamically instantiated objects from an object pool. I'm digging in to the code and replacing all Instantiate calls with the ProBuilder equivalent...

Share this post


Link to post
Share on other sites

Confirmed that this fixes the problem.

 

I did have to pass in the position Vector3 and rotation Quaternion parameters. These are normally not required parameters in GameObject.Instantiate, but I got errors when not passing them, using C# syntax.

 

The error given was: error CS1501: No overload for method `Instantiate' takes `1' arguments

Share this post


Link to post
Share on other sites

I think I'm going to take a look at this sometime this weekend.  Haven't written any custom actions for PlayMaker, but it seems like a worth while endeavor.  Time to look at some documentation.

Share this post


Link to post
Share on other sites

I think I'm going to take a look at this sometime this weekend.  Haven't written any custom actions for PlayMaker, but it seems like a worth while endeavor.  Time to look at some documentation.

 

Hey Tim- I know this is old, but would love to hear how this went. Lots of folks could use such a thing :)

Share this post


Link to post
Share on other sites

Confirmed that this fixes the problem.

 

I did have to pass in the position Vector3 and rotation Quaternion parameters. These are normally not required parameters in GameObject.Instantiate, but I got errors when not passing them, using C# syntax.

 

The error given was: error CS1501: No overload for method `Instantiate' takes `1' arguments

 

Checking on this now, and if not already, will make a case for this to be made same as regular Instantiate. Thanks!

Share this post


Link to post
Share on other sites

Hey Tim- I know this is old, but would love to hear how this went. Lots of folks could use such a thing :)

 

I'm still learning quite a bit about PlayMaker at the moment before I feel comfortable throwing anything out there. Kids and work killed most of my code time...so I've had little time for experimentation at the moment.  Hope to get back to this one soon...it is on my priority list right after dirty diapers at the moment.

 

UPDATE 1: 22 Jun 14 - 7pm Arizona (PST)

So, I've haven't worked with PlayMaker as much as I have ProBuilder, but this is moving forward.  I'm working on this right now.  

 

Baseline PlayMaker action code is working to instantiate a ProBuilderObject at the world origin with a zero'd rotation (Yay for no errors on my first run with PlayMaker).  I'm adding in properties now to allow for spawning at the location of another object (spawn point) or a defined coordinate (Vector3) and rotation (Vector3 converted to Euler Angles).

 

Lots of learning on how to get the UI for this to look right in PlayMaker, but there is progress thanks to a bottle for the baby and Alice and Wonderland occupying my oldest.

 

QUESTION:  Is there anything else that I should look into writing PlayMaker actions for as far as ProBuilder is concerned?  I know there is some runtime functionality that has some examples, but I was under the impression that the RT ProBuilder stuff was going to get massively overhauled in the future.  Is this something worth spending time on?

Share this post


Link to post
Share on other sites

Here we go.  Pretty sure this will cover any use case except for network instantiation because I know jack about doing network code right now.

 

This does the following:

  • Adds ProBuilder as a section of the PlayMaker Action Browser
  • Adds "Instantiate ProBuilder Object" as an available action
  • Action requires a Prefab to be defined or you get some nice warnings/errors from PlayMaker
  • Allows for assignment of a "SpawnPoint" GameObject.
  • Allows assigning of Vector3 Position for instantiation.  If there is a spawn point defined this is a local offset.
  • Allows assigning of Vector3 Rotation for instantiation.  This overrides the rotation of a spawn point if one is defined.  All Quaternion conversion is handled.
  • All Action variables have Tooltips for quick reference.
  • If only the Prefab is defined it will spawn based on prefabs transform properties.

Here's the code:

using UnityEngine;
using HutongGames.PlayMaker;
using ProBuilder2.Common;

[ActionCategory("ProBuilder")]
[Tooltip("Instantiates a Prefab created from a ProBuilder object")]
public class InstantiateProBuilderObject : FsmStateAction
{
	[RequiredField]
	[UIHint(UIHint.Variable)]
	[Tooltip("ProBuilder object to be instantiated")]
	public GameObject prefabObject;

	[Tooltip("Optional Spawn Point")]
	public FsmGameObject spawnPoint;

	[Tooltip("Position. NOTE: If Spawn Point is defined this is a local offset")]
	public FsmVector3 position;
	[Tooltip("Rotation.  NOTE: Overrides the rotation of a defined Spawn Point")]
	public FsmVector3 rotation;


	public override void Reset()
	{
		prefabObject = null;
		spawnPoint = null;
		position = new FsmVector3 { UseVariable = true };
		rotation = new FsmVector3 { UseVariable = true };

	}
	// Code that runs on entering the state.
	public override void OnEnter()
	{
		if (prefabObject != null)
		{
			Vector3 vPosition = prefabObject.transform.position;
			Quaternion qRotation = prefabObject.transform.rotation;

			if (!spawnPoint.IsNone  && 
				spawnPoint.Value != null)
			{
				vPosition = spawnPoint.Value.transform.position;
				qRotation = spawnPoint.Value.transform.rotation;
			}

			if (!position.IsNone)
			{
				if(!spawnPoint.IsNone)
					vPosition += position.Value;
				else
					vPosition = position.Value;
			}

			if (!rotation.IsNone)
				qRotation = Quaternion.Euler(rotation.Value);

			ProBuilder.Instantiate(prefabObject, vPosition, qRotation);
		}

		Finish();
	}
}

Copy into an appropriately named C# file and you are good to go.  If anyone wants this script in a unity package format, send me a PM.

 

Cheers!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×