Jump to content

Unhandled exception thrown while creating a colldier in Component:Start


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

For example in ThirdPersonControls

	virtual void Start()
	{
		smoothcameradistance = followdistance;
		auto entity = GetEntity();
		entity->SetPhysicsMode(PHYSICS_PLAYER);
		if (entity->GetMass() == 0.0f) entity->SetMass(78);
		entity->SetCollisionType(COLLISION_PLAYER);
		//here
		auto collider = CreateMeshCollider(entity->As<Model>());
		if (collider) entity->SetCollider(collider);

		camera = CreateCamera(entity->GetWorld());
		camera->SetPosition(0, eyeheight, 0);
		camera->SetRotation(0, 0, 0);
		camera->SetFov(70);
		currentcameraposition = camera->GetPosition(true);
		freelookrotation = entity->GetRotation(true);
	}

 

Link to comment
Share on other sites

Are you certain that entity->As<Model>() isn't returning NULL?

Why are you setting a collider? The player physics mode will create several cylinder shapes to handle the collision.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

6 hours ago, Josh said:

Are you certain that entity->As<Model>() isn't returning NULL?

Yes, i did check in my own component, just simplified it here.

 

6 hours ago, Josh said:

Why are you setting a collider? The player physics mode will create several cylinder shapes to handle the collision.

It's just an example for model that start map has. I don't use ThirdPersonControls or player physics mode in my project. Just wanted to apply a collision in Start om my units component. Have no problem with doing that outside of component while taking entities from world.

Link to comment
Share on other sites

  • 2 weeks later...

This works fine:

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto world = CreateWorld();
    auto model = LoadModel(world, "Models/Developer/Player/player.mdl");
    auto inst = model->Instantiate(world);
    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Solution

I see what was happening.

The mesh collider routine creates an instance of the model and collapses it, then uses that mesh data to build the shape. But it was using the default parameters for instantiation, which includes running the start function for any attached components on the new model. So it was creating an infinite recursive loop.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...