Problem with trigger in OntTriggerEnter2D in unity - function

I have a two objects, both of them have : rigidbody2D of type dynamic, collider2D set to trigger, same layer, same Z position. But they do not collider with each other. One of them has a simple script attached, which contains function OnTriggerEnter2D, which just debug.log some message. As you can guess the console doesn't print the message. No errors tho. Please help! I've also tried to restart unity, even the PC - doesn't work as well.
function :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log("DUOA");
}
}

Have a look at the Collision action matrix, you will not receive a trigger call from two dynamic Rigidbodies that both have a trigger collider component.
Change one of the Rigidbody types to Kinematic, which should resolve your issue.

Related

Call platform specific code from core project

I just Implemented ads for Android in my game using this guide.
It works fine, I have an interface in my core project that the Android Activity implements.
However my problem is that you need to send this implemented interface to the core project, and then pass it as a parameter to your first Screen, where you can use it, ex:
public MyGdxGame(PlatformSpecific ps) //Android class that handle fb-login and ads
{
this.ps = ps;
}
#Override
public void create ()
{
setScreen(new LoginScreen(this, ps);
}
This was fine for when I needed fb-login since I'm using that in the LoginScreen, but I want to be able to create my ads in other Screens (after a game is finished) by calling createAd-method in interface.
Do I have to keep passing ps between all the Screens just so I can use it in a Screen that only gets used quite rarely, or is there some way to get to this interface from my Screen without passing it to the constructor? Kind of like when you initiate an object, ex:
private PlatformSpecific ps = new PlatformSpecific();
Or does LibGdx have some library to support this scenario maybe? Worst case I could just pass ps between all constructors but feels like a pretty ugly solution.
Solution 1:
Store PlatformSpecific in a global static variable. That allows you to access anywhere in your code without passing it in every constructor.
Soluatio 2:
Have MyPlatformContext class which provides access to PlatformSpecific. Then pass this MyPlatformContext object to your screen constructors. If you extend your platform specific code later you do not have to change the screen constructors. Just edit MyPlatformContextMyPlatformContext class.
Pseudo code:
class MyPlatformContext {
private FacbookPlatform fb;
private AdmobPlatform admob
FacbookPlatform getFacebook() {
return fb;
}
...
}

Jodd proxy Unable to install breakpoint due to missing line number attributes

I have a jodd project that uses Proxetta and JTX for creating transactions over services classes. The issue is that when I try to debug a service class I receive :
Unable to install breakpoint due to missing line number attributes
I suspect that there has something to do with they way Proxetta generates my proxies classes as it seems that in Spring if you have no interface for a class the same happens.
I use Eclispe and here how Proxetta is initialized:
public void initProxetta() {
ProxyAspect txServiceProxy = new ProxyAspect(AnnotationTxAdvice.class,
new MethodAnnotationPointcut(Transaction.class) {
#Override
public boolean apply(MethodInfo mi) {
return isPublic(mi) &&
isTopLevelMethod(mi) &&
matchClassName(mi, "*ServiceImpl") &&
super.apply(mi);
}
});
proxetta = ProxyProxetta.withAspects(txServiceProxy);
proxetta.setClassLoader(this.getClass().getClassLoader());
}
Would you please try the following quickstart webapp1 example?
Its gradle project, so you can quickly import it in any IDE. In this example, we create proxy almost exactly like you above, but on actions (which should not make a difference). Now try to put a breakpoint into the IndexAction - this one gets proxified, for example. I am able to put break point there in IntelliJ IDEA.
Moreover, I dunno why Eclipse complains about the breakpoint in the service implementation class, since Proxetta as you used above creates a proxy subclass, and does not change the target class in any way. So when you put breakpoint in the service implementation code, it is in your class, not proxy class.
Finally, did you put BP on the method, or inside the code? If it is the first (on the method), then please try to put the BP inside the code of your service: eg on first line of the method body.

Base class variable is not accessible

I have two classes in Actionscript 3. I am using FlashBuilder 4.6. The SDK is 3.6A. The two classes are in a separate library. This library is referenced in the Active project.
My first (base) class is:
public class BaseDTO
{
public var errorCode:int;
public var errorMessage:String;
public function BaseDTO()
{
}
}
The second (derived) class is:
public class Configurations extends BaseDTO
{
}
In my active project (non-library), I am calling Configurations like this:
var c:Configurations = new Configurations();
c.errorCode = 0;
there are two references in two separate classes. Now the problems is that in first class which is basically a creationComplete handler of the application, I am getting a compile time error:
1119: Access of possibly undefined property errorCode through a
reference with static type dto.configs:Configurations.
And the other class which is calling the same code is throwing a runtime exception:
ReferenceError: Error #1056: Cannot create property errorCode on
dto.configs.Configurations.
I am not sure if I have explained it enough. Let me know if there are any other questions. I have been banging my head now for couple of hours now.
I have tried to create a new project, tried to use the same code to reference the configuration, and it works. Extremely strange.
Any Idea?
The Class was declared twice, in library and the project. Also, the namespace was same. Flex compiler should have raised warning on it though.

passing custom events between modules through parent application

I have created a custom event that I want to use to pass a string between two modules. The event looks like this:
package com.mypackage.events
{
import flash.events.Event;
public class ThumbDeleteEvent extends Event
{
public static const THUMBS_DELETED:String = "thumbsDeleted";
public var files:String;
public function ThumbDeleteEvent(type:String, files:String)
{
super(type);
this.files = files;
}
// Override the inherited clone() method.
override public function clone():Event {
return new ThumbDeleteEvent(type, files);
}
}
}
In one module I dispatch the event like so:
parentApplication.dispatchEvent(new ThumbDeleteEvent("parentApplication.thumbsDeleted", files));
and in another module I listen for the event like so:
public function init():void {
parentApplication.addEventListener("parentApplication.thumbsDeleted", onThumbsDelete);
}
if I use ThumbsDeleteEvent as the type passed in to the listener function like this:
public function onThumbsDelete(evt:ThumbDeleteEvent):void{
trace("thumb delete event for thumbs: "+evt.files);
}
I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert com.mypackage.events::ThumbDeleteEvent#26748a31 to com.mypackage.events.ThumbDeleteEvent.
if I just use Event as the type passed in to the listener function like this:
public function onThumbsDelete(evt:ThumbDeleteEvent):void{
if(evt is ThumbDeleteEvent){
trace("thumb delete event for thumbs: "+(evt as ThumbDeleteEvent).files);
}else{
var type:XML = describeType(evt);
trace(type.toXMLString());
}
}
It works but does not think it is a ThumbDeleteEvent type class (it hits the else statement) the xml output of describe type says its type is:
type name="com.mypackage.events::ThumbDeleteEvent"
What is going on here? If I put a breakpoint in the debugger it says the event is a ThumbDeleteEvent and I can see the files parameter and its right???
The issue here is that one swf has their definition of that class, and then the other swf has its own version of that exact same class. When trying to cast between them flash does a bytecode-check to see if the definitions are the same, and if you ever changed something in that as file without updating both with the exact same info you will run into this issue. That is, compile both swf-files, then change a space in the as-file, and compile only one swf file.
Urgh it's coming back to me, all those issues with shared code between different modules. I always just slug my way through these errors until I get it to work and can never really remember what it is since it can be so many issues.
Make sure both compiled swf-files have up-to-date-versions of the file.
Make sure both swf-files have same linkage-nesting to the code-file.
If that doesn't work [can't really remember since this issue is kind of like solve-once and copy to every other project].
See in which order things are added to ApplicationDomain and make sure nothing else has their own out-of-date-version of it through something imported in flash library
Move shared code into seperate code library linked in with "dynamic binding"
Try with sharing the Interface instead
Change how assets are loaded into the ApplicationDomain
Hopefully someone has more knowledge of this issue and can tell exactly what steps to use, but this is at least a starting point... I might have more time to research this and write a post about it sometime in the future later today.
Edit:
from another SO-thread Custom AS3 Class not Updating
This is the age old problem of what ultimately boils down to is the Verify Error. It happens when you embed "Class A" in one or more applications, modules, swfs, etc. Ultimately every output swf that uses "Class A" must be recompiled when "Class A" is changed. Otherwise you end up with a situation where 1 module has the newer implementation but others don't. This problem is compounded by the fact that the application domain is defined as a "first in wins" when it encounters a Class of the same name / package - meaning if the old one is referenced first, the newer one loaded later gets ignored.
The more permanent solution is to use class promotion to an RSL that ultimately allows the RSL to control the actual "Class A" reference in which it also implements an "IClassAImpl" interface that all modules use. This allows the compiler to cross link the reference with a signature it knows about without actually embedding the actual class itself.

'object' does not contain a constructor that takes 3 arguments

I'm trying my hand at generating spherical terrain in XNA 4.0, and am using an Icosahedron to achieve a sphere with evenly-distributed vertices. I'm fairly new to Xna, and I'm running into this problem trying to create a class that will handle defining all the vertices for the sphere.
here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Icosahedron_Test
{
class Icosahedron
{
public Icosahedron(int radius, int refinement, Vector3[] vertices)
: base(radius, refinement, vertices)
{
}
}
}
also, if anyone knows how to create an icosahedron, or can direct me to a tutorial, I'd be really grateful XD
In your code example, you are defining a new class called Icosahedron.
The code you provided is called a Constructor, which is a special method that is used to instantiate new objects.
public Icosahedron(int radius, int refinement, Vector3[] vertices)
: base(radius, refinement, vertices)
When writing
: base( .... )
You are attempting to call a base call of the current class you're defining.
C# supports a mechanism called Inheritance, which allows extending an object's behavior by extending another class. This can be used for adding/overriding some of the parent object's behavior and abilities.
In C#, all objects are derived from System.Object, and so, in your code you are attempting to call System.Object's constructor with 3 parameters, but this constructor method does not exist for System.Object.
You need to get a good reading on C# to get a grip on the basics :)
Your Icosahedron inherits object.
As the error message clearly states, you can't call base(...), since object doesn't have such a constructor.