UE4 setting sprite by using C++ - c++

I didn't figure out how can i set a sprite in actor class constructor by using its reference.
Reference is "PaperSprite'/Game/cc/combat/units/archer_Sprite_0.archer_Sprite_0'"
I want to make this sprite static. I think should use ConstructorHelpers::FObjectFinder . When i run the code below, i got this error:
sprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Sprite_comp"));
sprite->SetupAttachment(RootComponent);
ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/cc/combat/units/archer_Sprite_0.archer_Sprite_0'"));
//sprite->SetSprite(SpriteAssetObj.Object);
"Severity Code Description Project File Line Suppression State
Error C2664 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'T *' to 'UObject *' MyProject C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h 110
"
Any help or advice would be nice. Thanks in advance.

I want to make this sprite static.
ConstructorHelpers::FObjectFinder is for finding an asset.
In case of movement would be:
sprite->SetMobility(EComponentMobility::Type::Stationary);
I tested the code below without any problem. Are you sure ConstructorHelpers::FObjectFinder... is causing the error?
static ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/TEMP/Sprites/SP_TempSprite_1.SP_TempSprite_1'"));
if (SpriteAssetObj.Object)
{
UE_LOG(LogTemp, Warning, TEXT("PaperSprite loaded"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("PaperSprite not found"));
}
Don't forget to add Paper2D module to your YourGame.build.cs file:
PublicDependencyModuleNames.AddRange(new string[] { "Paper2D" });
And add to your file:
#include "PaperSprite.h"

Related

Using winrt::com_ptr<ID3D11Device1> with D3D11CreateDevice()?

I've been studying the code from the DirectXTK example project and trying to implement it in a new project. It seems like Microsoft recommends using WinRT in new projects, though, so I decided I would try to switch instances of WRL::ComPtr to winrt::com_ptr. I'm stuck, though, trying to move between ID3D11Device1 in the project's Game class and ID3DDevice in D3D11CreateDevice().
Here's the example code, slightly abstracted for simplicity's sake:
ComPtr<ID3D11Device1> global_device;
void CreateDevice()
{
...
ComPtr<ID3D11Device> local_device;
ThrowIfFailed(D3D11CreateDevice( ... local_device.ReleaseAndGetAddressOf() ... ));
ThrowIfFailed(local_device.As(&global_device));
}
And here's my approximation of it with WinRT:
com_ptr<ID3D11Device1> global_device;
void createDevice()
{
...
com_ptr<ID3D11Device> local_device;
check_hresult(D3D11CreateDevice( ... local_device.put() ... ));
global_device = local_device.as<ID3D11Device1>();
}
Every time I run it, though, I get these errors:
Error C2664 'HRESULT IUnknown::QueryInterface(const IID &,void **)': cannot convert argument 1 from 'const winrt::guid' to 'const IID &' HelloDX11 .\x64\Debug\Generated Files\winrt\base.h 1955
Message No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called HelloDX11 .\x64\Debug\Generated Files\winrt\base.h 1955
Message Reason: cannot convert from 'const winrt::guid' to 'const IID' HelloDX11 .\x64\Debug\Generated Files\winrt\base.h 1955
Message see reference to function template instantiation 'winrt::com_ptr<ID3D11Device1> winrt::com_ptr<ID3D11Device>::as<ID3D11Device1>(void) const' being compiled HelloDX11 .\game.cpp 47
Message see reference to function template instantiation 'winrt::com_ptr<ID3D11Device1> winrt::impl::as<To,ID3D11Device>(From *)' being compiled
with
[
To=ID3D11Device1,
From=ID3D11Device
] HelloDX11 .\x64\Debug\Generated Files\winrt\base.h 2377
I've gone over the docs for WRL::ComPtr.As() here, the docs for winrt::com_ptr.as() here, and the "conversion" example here about as many times as I can stand at this point. What am I missing?
Answer per IInspectable's comment:
"winrt::guid converts to GUID, as long as you include Unknwn.h before you include any C++/WinRT headers." See: https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/news#news-and-changes-in-windows-sdk-version-100177630-windows-10-version-1809

Converting Cocos2d code to ARC issues

I am trying to ARC enable a project and I am having a few issues when selecting files for ARC.
In the Ball class, the following line,
ballBody->SetUserData(self);
gives the error,
Cannot initialize a parameter of type 'void *' with an Ivalue of type 'Ball *const__strong'
In the Enemy.mm class, the following line,
enemyBody->SetUserData(enemySprite);
gives the error,
Cannot initialize a parameter of type 'void *' with an Ivalue of type 'CCPhysicsSprite*__strong'
In Enemy.h I have defined the above as:
b2Body* enemyBody;
CCPhysicsSprite* enemySprite; (in Enemy.m)
How can I solve these issues?
Bridge casting:
ballBody->SetUserData((__bridge void*)self);
enemyBody->SetUserData((__bridge void*)enemySprite);
and the reverse:
CCPhysicsSprite* enemySprite = (__bridge CCPhysicsSprite*)enemyBody->GetUserData();

Cannot convert from 'overloaded-function' to 'QLabel *'?

So, I am trying to use the following code to pass an object to a function in Qt, then convert it to a QLabel for further processing (it's part of an animation sequence):
void myAnimation(QObject* label)
{
QLabel *lbl = qobject_cast<QLabel*>label;
//more code.....
}
Yet, whenever I try to compile, I get the following two errors:
error: C2440: 'initializing' : cannot convert from 'overloaded-function' to 'QLabel *'
Context does not allow for disambiguation of overloaded function
and
error: C2146: syntax error : missing ';' before identifier 'label'
Why isn't my code working? Any help is appreciated. Thank you!
Try:
QLabel *lbl = qobject_cast<QLabel*>(label);
// ^ ^

Error 2664 - Can't convert from std::vector<...> to std::tr1::shared_ptr

Need help with an error message that I just can't figure out. I am getting the following:
Error 1 error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'Physics::Box2D' to 'std::tr1::shared_ptr<_Ty> &&' d:\visual studio 2010\projects\c++\test001\main.cpp 31 1 Test001
Not sure why, the code should work. I found sample code on StackOverFlow.com Maybe I am missing something.
Please help...newbie boost library user
//this code works fine...
Box2D *b = new Box2D();
b->Info();
//but this code fails...
vector< shared_ptr<Box2D> > boxes;
boxes.push_back( new Box2D() ); <--error happens here
The constructor for std::shared_ptr<T> taking a pointer to T is explicit, i.e. you can't implicitly convert to this type. Also, the error message doesn't seem to match the code. However, try this:
boxes.push_back(std::shared_ptr<Box2D>(new Box2D()));
... or
boxes.push_back(std::make_shared<Box2D>());

Getting a compilation error in VS2010 by following the first hello world example

i just started learning MFC..found a tutorial here http://bit.ly/j2uhHO ..just tried the same thing in VS2010 but getting a compilation error in this code..
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.TextOut(0, 0, "Hello, world!");
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
}
And the error is:
error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'
Can anyone solve this and suggest some mfc tutorials please..thank u..
The error tells you whats exactly wrong.
error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'
TextOutW() is expecting const CString & as the third parameter and you are passing const char [14]
You need to do:
dc.TextOut(0, 0, L"Hello, world!");
Which passes the third argument in the format desired by the function.
For MFC resources to refer, you see this.
The problem is that Windows by default uses wide characters wchar_t for texts. You would need
dc.TextOut(0, 0, L"Hello, world!");