Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here: https://discord.gg/zjNj5zZ

Target not detected by spawned observers

baroquedub
Posts: 2
Joined: Sun May 07, 2017 10:51 pm

Target not detected by spawned observers

Postby baroquedub » Sun May 07, 2017 11:13 pm

I have a player (character controller) with the Sight Target Behaviour component on it.
A little time into the game, I'm then spawning (from a Pool) prefabs that have the Observer 3D component on them.

When I added the Observer3D component on my prefab I got this error:

Code: Select all

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
UnityEngine.Transform:SetParent(Transform, Boolean)
Devdog.LosPro.ObserverBehaviour:InitSightTrigger() (at Assets/Devdog/LosPro/Scripts/Sight/Observer/ObserverBehaviour.cs:99)
Devdog.LosPro.ObserverBehaviour:get_sightTrigger() (at Assets/Devdog/LosPro/Scripts/Sight/Observer/ObserverBehaviour.cs:41)
Devdog.LosPro.Editors.ObserverBehaviourEditor:OnInspectorGUI() (at Assets/Devdog/LosPro/Scripts/Sight/Observer/Editor/ObserverBehaviourEditor.cs:24)
UnityEditor.DockArea:OnGUI()


So I changed the code of the Observer behaviour a little, on line 77:

Code: Select all

//protected virtual void Awake()
   protected virtual void OnSpawned()
        {
         if ( _eyes == null){
            _eyes= gameObject.transform;
         }
             InitSightTrigger();
            InvokeRepeating("UpdateSight", UnityEngine.Random.value * config.updateInterval, config.updateInterval);
        }


Essentially I've moved things from Awake to OnSpawned which I need to do for my spawning (I'm using CoreGameKit's PoolBoss)
and I've added a check that the _eyes variable has a reference to the gameobject's transform. I've checked this public variable at runtime, in the inspector, and that all appears to be fine, the variable references the each spawned gameObject's transform (not the prefab) and the gizmos appear on each of these observers.

The problem I have is that my target is never detected.

Does anyone have any advice? Seems odd that putting the script on a prefab should throw an error, and would assume that I can use spawned gameObjects as observres. AM I doing something stupid in the way I'm setting things up?

Thanks

baroquedub
Posts: 2
Joined: Sun May 07, 2017 10:51 pm

Re: Target not detected by spawned observers [SOLVED]

Postby baroquedub » Tue May 09, 2017 9:11 pm

I'll answer my own question since I've now worked it out..

Make sure you properly hook up the callbacks! (newbie error on my part)

Rewatching the ISightTargetCallbacks (coding) video helped me see where I'd made an error in my code.
https://www.youtube.com/watch?v=vYYkynDsF6g&index=5&list=PL_HIoK0xBTK7P_QtpeweRuhahBPGZ-q_X


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest