Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spawning Controller Prefab with Matched Spline Prefab Using Pool Manager
#1
Sad 
I have a spline and a controller prefabs. Controller has a Spline Controller Script and a spaceship prefab. Spline Controller has a Spline to follow. I'm using a pool manager to spawn-despawn Controller prefabs. My problem is that spawning Controllers doesn't follow any spline, just staying at 0,0,0 point.
Reply
#2
After spawning a controller you might need to start playing by calling Play(). Also, please check if the controller has a source spline set. Perhaps it got lost during the spawn process some way.
Reply
#3
Sad 
I've tried to call Play() method and didn't work. This is Controller(Clone)001 and 2,3,4,5, ... at Runtime: 
[Image: kBO50v.jpg]
[url=http://hizliresim.com/kBO50v][/url]
Reply
#4
Also these are Curvy Spline and trigger scripts:
   
Code:
using UnityEngine;
using System.Collections;
using PathologicalGames;
using FluffyUnderware.Curvy.Controllers;

public class TriggerScript : MonoBehaviour {
   public Transform enemy;
   public FluffyUnderware.Curvy.CurvySpline curvySpline;
   private SplineController sc;
   private int count = 0;
   void OnTriggerEnter(Collider other)
   {
       Debug.Log("Triggered.");
       Enemy1Create();
   }

   void Enemy1Create()
   {
       sc = enemy.GetComponent<SplineController>();
       PoolManager.Pools["EnemyPool"].Spawn(enemy);
       sc.Spline = curvySpline;
       //Instantiate(enemy, Vector3.zero, Quaternion.identity);
       sc.Play();

       count++;
       if (count < 3)
           Invoke("Enemy1Create", 0.7f);
   }
}
Reply
#5
To remove the pooling manager from the game for testing purposes: If you use plain vanilla Instantiate() instead of using the pooling manager, does it work then?
Reply
#6
I did some changes and it worked but not with my way. I'm working on it.
Reply
#7
Ok, using instantiate() instead of pool manager has worked. But i want to use pool manager.

When i use pool manager, i get this error at the beginning.

IndexOutOfRangeException: Array index is out of range.
FluffyUnderware.Curvy.CurvySplineSegment.GetOrientationUpFast (Single localF) (at Assets/Packages/Curvy/Base/CurvySplineSegment.cs:1974)
FluffyUnderware.Curvy.CurvySpline.GetOrientationUpFast (Single tf) (at Assets/Packages/Curvy/Base/CurvySpline.cs:953)
FluffyUnderware.Curvy.Controllers.SplineController.getInterpolatedSourcePosition (FluffyUnderware.Curvy.CurvySplineBase spline, Single tf, UnityEngine.Vector3& position, UnityEngine.Vector3& tangent, UnityEngine.Vector3& up) (at Assets/Packages/Curvy/Controllers/SplineController.cs:566)
FluffyUnderware.Curvy.Controllers.SplineController.GetInterpolatedSourcePosition (Single tf, UnityEngine.Vector3& position, UnityEngine.Vector3& tangent, UnityEngine.Vector3& up) (at Assets/Packages/Curvy/Controllers/SplineController.cs:378)
FluffyUnderware.Curvy.CurvyController.applyPositionAndRotation (Single tf) (at Assets/Packages/Curvy/Base/CurvyController.cs:1142)
FluffyUnderware.Curvy.CurvyController.Prepare () (at Assets/Packages/Curvy/Base/CurvyController.cs:712)
FluffyUnderware.Curvy.Controllers.SplineController.Prepare () (at Assets/Packages/Curvy/Controllers/SplineController.cs:241)
FluffyUnderware.Curvy.CurvyController.OnValidate () (at Assets/Packages/Curvy/Base/CurvyController.cs:636)
FluffyUnderware.Curvy.Controllers.SplineController.OnValidate () (at Assets/Packages/Curvy/Controllers/SplineController.cs:220)

Latest trigger script:
 
Code:
using UnityEngine;
using System.Collections;
using PathologicalGames;
using FluffyUnderware.Curvy.Controllers;

public class TriggerScript : MonoBehaviour {
   public GameObject enemy;
   public FluffyUnderware.Curvy.CurvySpline curvySpline;
   private SplineController sc;
   private int count = 0;

   void Start()
   {
       
   }
   void OnTriggerEnter(Collider other)
   {
       Debug.Log("Triggered.");
       sc = enemy.GetComponent<SplineController>();
       sc.Spline = curvySpline;
       Debug.Log(curvySpline);

       Enemy1Create();
   }

   void Enemy1Create()
   {
       curvySpline.Refresh();
       sc.Play();
       //Pool.Instance.Activate(0, Vector3.zero, Quaternion.identity);
       //Instantiate(enemy, Vector3.zero, Quaternion.identity);
       PoolManager.Pools["EnemyPool"].Spawn(enemy);

       Debug.Log(sc.IsInitialized);
       count++;
       if (count < 3)
           Invoke("Enemy1Create", 0.7f);
   }
}
Reply
#8
Ok done. Thank you for your help. I've done with two lines of code:
Code:
PoolManager.Pools["EnemyPool"].Spawn(enemy).GetComponent<SplineController>().Spline = curvySpline;
curvySpline.Refresh();
Reply
#9
Guess what happened. Enemy spaceships which are attached to the controller doesn't appear on mobile. I mean i can't see any ships. But there is no problem with testing on computer. Also i've tried with another waypoint system and no problem with that.
Reply
#10
Spawning means pre-instantiate e.g. at startup, then enabling the GameObject on demand. So if you have a controller GameObject (prefab or not) without a spline embedded (i.e. spawning a spline that has a controller as child object or a parent object holding a spline and a controller as children), the reference to any "external" spline will be lost.

After enabling it, you'll need to set the spline at least. If the spline was contained within the prefab, you'll need to Refresh() the spline before setting it to the controller.

That should do the trick...
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Spline Controller restart FlebusCroqus 2 28 05-16-2019, 07:35 PM
Last Post: FlebusCroqus
  Spline Controller Position Force Update ? UsernameHed 1 36 05-16-2019, 12:20 PM
Last Post: _Aka_
  Curvy Coppy all points of a Spline Into Another UsernameHed 3 91 05-13-2019, 11:37 AM
Last Post: _Aka_
  Add Volume to the Volume Controller Dynamically ACBrandon 9 270 04-18-2019, 10:44 AM
Last Post: _Aka_

Forum Jump: