Assertion failure when adding a StaticSprite2D on a extension of Node class

[Edit] Solution: Use a custom LogicComponent instead.


The Node class is not designed to be subclass by user. See also the discussion in

Hello folks,

I have this problem when I add a Sprite2D to a StaticSprite2D component created from a custom class that extends Urho3D::Node. I’m using VS 2015 with Urho 1.6. This is my custom class:

NodeExt.h :

#pragma once
#include "stdafx.h"

using namespace Urho3D;

class NodeExt : public Node
	URHO3D_OBJECT(NodeExt, Node);

	NodeExt(Context* context);
	virtual ~NodeExt();


#include "NodeExt.h"

NodeExt::NodeExt(Context* context) : Node(context)
	RigidBody2D* body = CreateComponent<RigidBody2D>();

	CollisionBox2D* box = CreateComponent<CollisionBox2D>();
	box->SetSize(Vector2(0.32f, 0.32f));

	ResourceCache* cache = GetSubsystem<ResourceCache>();
	StaticSprite2D* staticSprite = CreateComponent<StaticSprite2D>();
	staticSprite->SetSprite(cache->GetResource<Sprite2D>("Images/ship.png")); // This is where the error happens


And the error:

Now, if I comment the line where the SetSprite happens, everything proceeds as usual. And if I use a Urho3D::Node instead my custom class, using the same code, no error happens.

Is there something missing that I should include in my custom class to successfully extend Urho3D::Node?

The Node class is not designed to be subclass by user. See also the discussion in Alternatives to node subclassing?.

1 Like

Oh I see, thanks for your answer.

Should I mark this as solved? I know it technically didn’t get solved but it seems like it’s not possible.