I want to take a texture2D that’s determined during runtime and return a sprite that’s created from it.
I can’t find any pages describing how to do this in Blueprints or in C++, and the documentation is very sparse to all but those with prior knowledge of how this engine works (I’m not quite there yet). Everything talks about creating a sprite offline in order to use it in the game, but that’s not an option for what I’m looking to do.
I couldn’t find anything either but lucky for you now have something on my screen. If someone stands up and slaps us with a better solution we’ll only both benefit!
See:
Scaling is interesting. I multiply up the X and Z scales with 100.0/texture size then the actor seems about the size I expect.
I should also say - that to define my own material I also applied a funny workaround.
- Blueprint a paper sprite actor in the editor
- Setup the material in this blueprint to work as you want
- Create one of these blueprinted actors at runtime
- Post creation DuplicateObject the Sprite object. This allows you to point at different textures, and keeps the material settings.
Again, someone is welcome to smack me on the forehead with a mackerel or other dead or otherwise suitably sized fish / better method, but this works.
Is the function you’re working on meant to be used within a blueprint? I’ve got it similarly implemented, but am unsure how to hook up the pWorld object as I get a circular dependency when I set it to the current map.
pWorld in my case comes from GetWorld in my GameMode class.
I only use the function in C++ at this point.
btw, this is the blind leading the blind, any “advanced” knowledge I may seem to have is simply one more day of heads hitting brick walls. What you are doing is somewhat outside the Paper2D box - hence the lack of documentation. In my case I’m still not sure that abusing Paper2D has been the right approach, though it has been fun.
it seems to be holding up to the flogging we’re giving it so far. Hopefully we can demonstrate the value of this capability and make a case for a more formal implementation from those who may know a cleaner way to wire it. Thanks again for your insights.
No worries! You can mark my response as an answer then
It is correctly marked as answered. Thanks.
Unfortuantly my solution doesn’t work - its editor only.
error C2039: ‘InitializeSprite’ : is not a member of ‘UPaperSprite’
MainFrameActions: Packaging (Windows (32-bit)): UnrealBuildTool: c:\program files\unreal engine\4.7\engine\plugins\2d\paper2d\source\paper2d\classes\PaperSprite.h(43) : see declaration of ‘UPaperSprite’
Most of the sprite building functions are editor only.
Back to square one.
Yes, while your method did solve the problem of generating sprites, the downstream part of the solution tanked, not because it had to run in the editor, which would have become a nuisance later, but because the generated sprite didn’t seem to allow any kind of collider to attach to it. It was exciting for a while though. Thanks.