Jump to content

Add model with KSPParticleEmitter to gameobject


Recommended Posts

I am trying to add a model to a gameobject A, my plan is to create a new gameobject B with the model and attach B to A as child.

But the KSPparticleemitter in B could not be got by GetComponentInChildren<KSPParticleEmitter>() after attachment. 

 

GameObject DebObj = GameDatabase.Instance.GetModel(SunbeamFXPath);
KSPParticleEmitter pe = DebObj.GetComponentInChildren<KSPParticleEmitter>();
Debug.Log("<color=green>[RayMonitor] </color>Deb PE = "+ pe.name);//This log will return the name 
DebObj.transform.SetParent(RayObj.transform);
KSPParticleEmitter rpe = RayObj.GetComponentInChildren<KSPParticleEmitter>();
Debug.Log("<color=green>[RayMonitor] </color>Ray PE = " + rpe.name);//This log will return NRE

Is there better solutions?

Edited by flywlyx
Link to comment
Share on other sites

Don't mess with the original models in GameDatabase. Instantiate a new GameObject using them instead or you'll blow things up later. I would be surprised if your first log was working; GetComponentInChildren only returns a component on active GameObjects (unless you use one of its overloads) and none of the model stuff should be active

Link to comment
Share on other sites

  • 2 weeks later...
On 8/19/2020 at 9:16 PM, xEvilReeperx said:

Don't mess with the original models in GameDatabase. Instantiate a new GameObject using them instead or you'll blow things up later. I would be surprised if your first log was working; GetComponentInChildren only returns a component on active GameObjects (unless you use one of its overloads) and none of the model stuff should be active

Yeah, I noticed later, if the GO is not active, then GetComponentInChildren still give you result, but if child is not active GetComponentInChildren will return nothing.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...