playMaker

Author Topic: Error when adding Rigidbody + Force in FSM  (Read 1857 times)

Singularity

  • Playmaker Newbie
  • *
  • Posts: 13
Error when adding Rigidbody + Force in FSM
« on: November 19, 2014, 05:05:21 AM »
Hello,

Apologies in advance if this should be in the bug section.

In my game I have a tree prefab, this prefab holds an FSM.

The FSM works perfectly but throws up an error.

The prefab itself does not have a rigid body component, I add this in the fsm only when the player interacts (in this case chops down!) with the tree.  As I will have thousands of trees in my scene this is intended to save performance (I don't want thousands of rigidbodys if I don't need them)

The FSM adds the rigidbody just fine and then in the next state applies a force to make the tree fall over.

The force is what throws up the error.  Playmaker doesn't know the FSM has added a rigid body, so it tells me the object requires one.

It's only an editor error, It's fine at runtime.  I have as many of these errors as trees in the scene though so it is annoying!

So I'm wondering;

Ideally - is this a bug that can be fixed?

Am I worrying needlessly about performance, should I just add a rigid body to the object and leave it on permanently, only adding a force in the FSM?

Should I just ignore it?

Maybe I should add a rigidbody to the prefab but disable and enable it as necessary in the FSM?

Any thoughts most welcome.

Thanks

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Error when adding Rigidbody + Force in FSM
« Reply #1 on: November 19, 2014, 05:52:25 PM »
This is a tricky one.

Right now the error checker doesn't know that you add the rigid body at runtime. So the error is harmless, but also annoying...

You could turn off the required component check:
Preferences > Error Checking > Check for Required Components.

But then you lose all checking for required components.

I'll think about the best way to handle this. I'm open to suggestions :)

I think you'd have to test the performance pros and cons of adding the rigidbody at runtime. Maybe have the rigidbody on a child that you activate/deactivate. Or switch the IsKinematic flag on/off. 

I wouldn't assume that adding the component at runtime is the best perf solution (e.g., it could trigger physics engine initialization). You need to test and/or search Unity forums for advice on this.
« Last Edit: November 19, 2014, 05:54:41 PM by Alex Chouls »

Singularity

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Error when adding Rigidbody + Force in FSM
« Reply #2 on: November 20, 2014, 11:44:07 AM »
Thanks for your response Alex, I thought it was a bit of an odd case!

I'll play around with a few options and see what I can come up with.

Definitely keen to hear of any interesting solutions people might have though, let me know if you think of anything.